'use client'; import { useTranslation } from '../../../i18n/useTranslation'; import type { NamespaceCategory } from '../hooks/useNamespaceCategories'; import { useModalAnimation } from '../hooks/useModalAnimation'; type Props = { isOpen: boolean; onClose: () => void; newCategoryLabel: string; setNewCategoryLabel: (value: string) => void; onCreateCategory: () => void; uncategorizedNamespaces: string[]; categoriesWithKnownNamespaces: NamespaceCategory[]; namespaces: string[]; assignNamespaceByCategory: Record; setAssignNamespaceByCategory: (next: Record | ((prev: Record) => Record)) => void; expandedCategoryId: string | null; setExpandedCategoryId: (value: string | null | ((prev: string | null) => string | null)) => void; dragNamespace: string | null; setDragNamespace: (value: string | null) => void; addNamespaceToCategory: (categoryId: string, namespace: string) => void; removeNamespaceFromCategory: (categoryId: string, namespace: string) => void; deleteCategory: (categoryId: string) => void; }; export default function CategoryManagerModal({ isOpen, onClose, newCategoryLabel, setNewCategoryLabel, onCreateCategory, uncategorizedNamespaces, categoriesWithKnownNamespaces, namespaces, assignNamespaceByCategory, setAssignNamespaceByCategory, expandedCategoryId, setExpandedCategoryId, dragNamespace, setDragNamespace, addNamespaceToCategory, removeNamespaceFromCategory, deleteCategory, }: Props) { const { t } = useTranslation(); const { isRendered, isVisible } = useModalAnimation(isOpen); if (!isRendered) return null; return (
{/* Header */}
Admin

{t('autofix.kef9de7f0')}

{t('autofix.kc4671abe')}

{/* Body */}
{/* Create category row */}
setNewCategoryLabel(e.target.value)} placeholder={t('autofix.ke52ed6e9')} className="w-56 rounded-2xl border border-slate-200 bg-white px-4 py-2 text-sm shadow-sm placeholder:text-slate-400 focus:outline-none focus:ring-2 focus:ring-slate-900/20 transition" />
{/* Uncategorized pool */}

{t('autofix.k505ebdae')}

{uncategorizedNamespaces.map((ns) => ( setDragNamespace(ns)} className="cursor-grab rounded-full border border-slate-200 bg-white px-3 py-1 text-xs font-medium text-slate-700 shadow-sm hover:border-slate-300 hover:bg-slate-50 transition" title={t('autofix.k66edf1eb')} > {ns} ))} {uncategorizedNamespaces.length === 0 && ( {t('autofix.k741a01f7')} )}
{/* Category list */}
{categoriesWithKnownNamespaces.map((cat) => { const availableToAssign = namespaces.filter((ns) => !cat.namespaces.includes(ns)); const selectValue = assignNamespaceByCategory[cat.id] ?? ''; const isExpanded = expandedCategoryId === cat.id; return (
{ if (!dragNamespace) return; if (expandedCategoryId !== cat.id) setExpandedCategoryId(cat.id); }} onDragOver={(e) => e.preventDefault()} onDrop={() => { if (dragNamespace) { addNamespaceToCategory(cat.id, dragNamespace); setDragNamespace(null); } }} className="rounded-[20px] border border-white/80 bg-white/70 backdrop-blur overflow-hidden shadow-sm" > {/* Category header row */}
setExpandedCategoryId((prev) => (prev === cat.id ? null : cat.id))} >
{cat.label} {cat.namespaces.length} {isExpanded ? t('autofix.k5daa1471') : t('autofix.k893106ba')}
{cat.isCustom && ( )}
{isExpanded && (
{cat.namespaces.map((ns) => ( setDragNamespace(ns)} className="group cursor-grab inline-flex items-center rounded-full border border-indigo-200 bg-indigo-50 px-3 py-1 text-xs font-medium text-indigo-700 hover:border-indigo-300 transition" > {ns} ))} {cat.namespaces.length === 0 && ( {t('autofix.kf3c3223a')} )}
)}
); })}
{/* Footer */}
); }