import { useId } from 'react' import { Plus, Pencil, Trash2, Pipette, Tags, Loader2 } from 'lucide-react' import { DialogButton, DialogFooter, DialogHeader, DialogSection, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell' import { Tooltip } from '../shared/Tooltip' import ConfirmDialog from '../shared/ConfirmDialog' import { SettingRows, SettingsCard, SettingsHint, StatusPill, SETTINGS_BUTTON_PRIMARY, SETTINGS_ICON_BUTTON } from '../Settings/settingsKit' import { CATEGORY_ICON_MAP, ICON_LABELS, getCategoryIcon } from '../shared/categoryIcons' import { useTranslation } from '../../i18n' import { ICON_NAMES, PRESET_COLORS, useCategoryAdmin } from './useCategoryAdmin' export default function CategoryManager() { const { categories, showForm, editingId, form, setForm, isSaving, isLoading, deleteId, setDeleteId, colorInputRef, handleStartEdit, handleStartCreate, handleCancel, handleSave, handleDelete, isPresetColor, } = useCategoryAdmin() const { t } = useTranslation() const labelId = useId() const PreviewIcon = getCategoryIcon(form.icon) const formOpen = showForm || editingId !== null const saveDisabled = isSaving || !form.name.trim() const categoryDialog = ( } tint={NEUTRAL_TINT} labelId={labelId} onClose={handleCancel} eyebrow={editingId ? t('common.edit') : t('categories.new')} titleInput={{ value: form.name, onChange: name => setForm(prev => ({ ...prev, name })), label: t('categories.namePlaceholder'), placeholder: t('categories.namePlaceholder'), autoFocus: true, onKeyDown: e => { if (e.key === 'Enter' && !saveDisabled) void handleSave() }, }} /> } footer={ {t('common.cancel')} {isSaving ? t('common.saving') : editingId ? t('categories.update') : t('categories.create')} } >
{ICON_NAMES.map(name => { const Icon = CATEGORY_ICON_MAP[name] const isSelected = form.icon === name return ( ) })}
{PRESET_COLORS.map(color => (
{form.name || t('categories.defaultName')}
) return ( 0 ? {categories.length} : undefined} action={ } > {isLoading ? (
) : categories.length === 0 ? (
{t('categories.empty')}
) : ( {categories.map(cat => { const Icon = getCategoryIcon(cat.icon) return (
{cat.name} {cat.color}
) })}
)} {formOpen && categoryDialog} setDeleteId(null)} onConfirm={() => { if (deleteId !== null) void handleDelete(deleteId) }} message={t('categories.confirm.delete')} confirmLabel={t('common.delete')} danger />
) }