import React, { useMemo } from 'react'; import { parseSnippetVariables } from '../domain/snippetVariables'; import { Check, Clock, Keyboard, Loader2, Package, RotateCcw, Trash2 } from 'lucide-react'; import { cn } from '../lib/utils'; import SelectHostPanel from './SelectHostPanel'; import { AsidePanel, AsidePanelContent, AsidePanelFooter } from './ui/aside-panel'; import { Button } from './ui/button'; import { Card } from './ui/card'; import { Input } from './ui/input'; import { SnippetScriptEditor } from './snippets/SnippetScriptEditor'; import { Tooltip, TooltipContent, TooltipTrigger } from './ui/tooltip'; import { Combobox } from './ui/combobox'; import { DistroAvatar } from './DistroAvatar'; import { HistoryItem } from './SnippetsHistoryItem'; // eslint-disable-next-line @typescript-eslint/no-explicit-any type SnippetsRightPanelProps = Record; export const SnippetsRightPanel: React.FC = ({ rightPanelMode, hosts, customGroups, targetSelection, handleTargetSelect, handleTargetPickerBack, availableKeys, proxyProfiles, managedSources, onSaveHost, onCreateGroup, t, handleClosePanel, editingSnippet, onDelete, handleSubmit, setEditingSnippet, packageOptions, selectedPackage, packages, onPackagesChange, shortkeyError, setShortkeyError, isRecordingShortkey, setIsRecordingShortkey, openTargetPicker, targetHosts, shellHistory, handleHistoryScroll, historyScrollRef, visibleHistory, saveHistoryAsSnippet, handleCopy, copiedId, hasMoreHistory, isLoadingMore, loadMoreHistory, }) => { const detectedVariables = useMemo( () => parseSnippetVariables(editingSnippet?.command || ''), [editingSnippet?.command], ); if (rightPanelMode === 'select-targets') { return ( ); } if (rightPanelMode === 'edit-snippet') { return ( {editingSnippet.id && ( {t('common.delete')} )} } > {/* Action Description */}

{t('snippets.field.description')}

setEditingSnippet({ ...editingSnippet, label: e.target.value })} className="h-10" spellCheck={false} />
{/* Package */}

{t('snippets.field.package')}

{ setEditingSnippet({ ...editingSnippet, package: val }); // If selecting an implicit parent path, persist it to packages if (val && !packages.includes(val)) { onPackagesChange([...packages, val]); } }} placeholder={t('snippets.field.packagePlaceholder')} allowCreate={true} onCreateNew={(val) => { if (!packages.includes(val)) { onPackagesChange([...packages, val]); } }} createText={t('snippets.field.createPackage')} icon={} triggerClassName="h-10" />
{/* Script */} setEditingSnippet({ ...editingSnippet, command })} />

{t('snippets.field.variablesHelp')}

{detectedVariables.length > 0 && (
{t('snippets.field.variablesDetected')}: {detectedVariables.map((variable) => ( {variable.name} {variable.defaultValue !== undefined && ( ({t('snippets.field.variableDefault', { value: variable.defaultValue })}) )} ))}
)}
{/* No Auto Run */} {/* Shortkey */}

{t('snippets.field.shortkey')}

{editingSnippet.shortkey && ( {t('snippets.shortkey.clear')} )}
{shortkeyError && (

{shortkeyError}

)}

{t('snippets.shortkey.hint')}

{/* Targets */}

{t('snippets.targets.title')}

{targetHosts.length === 0 ? ( ) : (
{targetHosts.map((h) => (
{h.hostname}
{h.protocol || 'ssh'}, {h.username}
))}
)}
{/* Footer */}
); } if (rightPanelMode === 'history') { return ( {/* History List */}
{visibleHistory.length === 0 ? (

{t('snippets.history.emptyTitle')}

{t('snippets.history.emptyDesc')}

) : ( <> {visibleHistory.map((entry) => ( handleCopy(entry.id, entry.command)} isCopied={copiedId === entry.id} /> ))} {hasMoreHistory && (
{isLoadingMore ? ( ) : ( )}
)} )}
); } return null; };