import { FileCode, Search, Zap } from 'lucide-react'; import React, { memo, useMemo, useState } from 'react'; import { useI18n } from '../../application/i18n/I18nProvider'; import { cn } from '../../lib/utils'; import type { Snippet } from '../../types'; import { FixedSizeVirtualList } from '../ui/FixedSizeVirtualList'; import { Input } from '../ui/input'; import { SnippetCommandTooltipContent } from './SnippetCommandTooltipContent'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip'; const ROW_HEIGHT = 34; export interface SnippetCommandPickerProps { snippets: Snippet[]; selectedId?: string | null; onSelect: (snippet: Snippet) => void; className?: string; showTitle?: boolean; } export const SnippetCommandPicker = memo(function SnippetCommandPicker({ snippets, selectedId, onSelect, className, showTitle = true, }: SnippetCommandPickerProps) { const { t } = useI18n(); const [search, setSearch] = useState(''); const filtered = useMemo(() => { const q = search.trim().toLowerCase(); const sorted = [...snippets].sort((a, b) => a.label.localeCompare(b.label)); if (!q) return sorted; return sorted.filter( (snippet) => snippet.label.toLowerCase().includes(q) || snippet.command.toLowerCase().includes(q) || (snippet.package || '').toLowerCase().includes(q), ); }, [search, snippets]); const listItems = useMemo( () => filtered.map((snippet) => ({ key: snippet.id, snippet })), [filtered], ); return (
{showTitle && (

{t('systemManager.tmux.pickSnippet')}

)}
setSearch(e.target.value)} placeholder={t('snippets.searchPlaceholder')} className="h-7 border-none bg-background/60 pl-7 text-xs" disabled={snippets.length === 0} />
{snippets.length === 0 ? (

{t('systemManager.tmux.pickSnippetEmpty')}

) : filtered.length === 0 ? (
{t('common.noResultsFound')}
) : ( item.key} renderItem={(item) => { const { snippet } = item; const selected = selectedId === snippet.id; return ( ); }} /> )}
); });