{editingTemplate === tmpl.id ? (
setEditTemplateName(e.target.value)}
onBlur={() => handleRenameTemplate(tmpl.id)}
onKeyDown={e => { if (e.key === 'Enter') handleRenameTemplate(tmpl.id); if (e.key === 'Escape') setEditingTemplate(null) }}
/>
) : (
)}
{ setEditingTemplate(tmpl.id); setEditTemplateName(tmpl.name) }}
>
handleDeleteTemplate(tmpl.id)}
>
{/* Expanded content */}
{expandedId === tmpl.id && (
{categories.map(cat => {
const catItems = items.filter(i => i.category_id === cat.id)
return (
{/* Category header */}
{editingCatId === cat.id ? (
setEditCatName(e.target.value)}
onBlur={() => handleRenameCategory(cat.id)}
onKeyDown={e => { if (e.key === 'Enter') handleRenameCategory(cat.id); if (e.key === 'Escape') setEditingCatId(null) }}
/>
) : (
{cat.name}
)}
{catItems.length}
{ setAddingItemToCatId(addingItemToCatId === cat.id ? null : cat.id); setNewItemName(''); setTimeout(() => addItemRef.current?.focus(), 30) }}
>
{ setEditingCatId(cat.id); setEditCatName(cat.name) }}
>
handleDeleteCategory(cat.id)}
>
{/* Items */}
{(catItems.length > 0 || addingItemToCatId === cat.id) && (
{catItems.map(item => (
{editingItemId === item.id ? (
<>
setEditItemName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') handleRenameItem(item.id); if (e.key === 'Escape') setEditingItemId(null) }}
/>
handleRenameItem(item.id)}>
setEditingItemId(null)}>
>
) : (
<>
{item.name}
{ setEditingItemId(item.id); setEditItemName(item.name) }}
>
handleDeleteItem(item.id)}
>
>
)}
))}
{/* Add item inline */}
{addingItemToCatId === cat.id && (
)}
)}
)
})}
{/* Add category */}
{addingCategory ? (
setNewCatName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') handleAddCategory(); if (e.key === 'Escape') { setAddingCategory(false); setNewCatName('') } }}
placeholder={t('admin.packingTemplates.categoryName')}
/>
{ setAddingCategory(false); setNewCatName('') }}>
) : (
)}