'use client' import { useState, useMemo } from 'react' import { Search, Plus, Pencil, Trash2, Eye, ChevronUp, ChevronDown, Database, } from 'lucide-react' import type { CatalogMeta, CatalogEntry } from '@/lib/sdk/catalog-manager/types' interface CatalogTableProps { catalog: CatalogMeta entries: CatalogEntry[] searchQuery: string onSearchChange: (query: string) => void onEditCustomEntry: (entry: CatalogEntry) => void onDeleteCustomEntry: (entryId: string) => void onAddEntry: () => void } type SortField = 'id' | 'name' | 'category' | 'type' type SortDirection = 'asc' | 'desc' export default function CatalogTable({ catalog, entries, searchQuery, onSearchChange, onEditCustomEntry, onDeleteCustomEntry, onAddEntry, }: CatalogTableProps) { const [sortField, setSortField] = useState('name') const [sortDirection, setSortDirection] = useState('asc') const handleSort = (field: SortField) => { if (sortField === field) { setSortDirection(prev => (prev === 'asc' ? 'desc' : 'asc')) } else { setSortField(field) setSortDirection('asc') } } const sortedEntries = useMemo(() => { const sorted = [...entries].sort((a, b) => { let aVal = '' let bVal = '' switch (sortField) { case 'id': aVal = a.id bVal = b.id break case 'name': aVal = a.displayName bVal = b.displayName break case 'category': aVal = a.category || '' bVal = b.category || '' break case 'type': aVal = a.source bVal = b.source break } const cmp = aVal.localeCompare(bVal, 'de') return sortDirection === 'asc' ? cmp : -cmp }) return sorted }, [entries, sortField, sortDirection]) const SortIcon = ({ field }: { field: SortField }) => { if (sortField !== field) { return ( ) } return sortDirection === 'asc' ? ( ) : ( ) } return (
{/* Search & Add Header */}
onSearchChange(e.target.value)} placeholder="Eintraege durchsuchen..." className="w-full pl-9 pr-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-violet-500 focus:border-transparent" />
{catalog.allowCustom && ( )}
{/* Table */}
{catalog.categoryField && ( )} {sortedEntries.length === 0 ? ( ) : ( sortedEntries.map((entry) => ( {catalog.categoryField && ( )} )) )}
handleSort('name')} > Name handleSort('category')} > Kategorie handleSort('type')} > Quelle Aktionen

{searchQuery ? `Keine Eintraege gefunden fuer "${searchQuery}"` : 'Keine Eintraege vorhanden'}

{entry.displayName}

{entry.displayDescription && (

{entry.displayDescription}

)}
{entry.category || '\u2014'} {entry.source === 'system' ? ( System ) : ( Benutzerdefiniert )}
{entry.source === 'system' ? ( ) : ( <> )}
{/* Footer with count */} {sortedEntries.length > 0 && (
{sortedEntries.length} {sortedEntries.length === 1 ? 'Eintrag' : 'Eintraege'} {searchQuery && ` (gefiltert)`}
)}
) }