import ReactDOM from 'react-dom' import { useState } from 'react' import { Plus, Trash2, X } from 'lucide-react' import { FONT, NOTE_COLORS } from './CollabNotes.constants' import { EditableCatName } from './CollabNotesEditableCatName' // ── Category Settings Modal ────────────────────────────────────────────────── interface CategorySettingsModalProps { onClose: () => void categories: string[] categoryColors: Record onSave: (colors: Record) => void onRenameCategory: (oldName: string, newName: string) => Promise t: (key: string) => string } export function CategorySettingsModal({ onClose, categories, categoryColors, onSave, onRenameCategory, t }: CategorySettingsModalProps) { const [localColors, setLocalColors] = useState({ ...categoryColors }) const [renames, setRenames] = useState>({}) // { oldName: newName } const [newCatName, setNewCatName] = useState('') const handleColorChange = (cat, color) => { setLocalColors(prev => ({ ...prev, [cat]: color })) } const handleAddCategory = () => { if (!newCatName.trim() || localColors[newCatName.trim()]) return setLocalColors(prev => ({ ...prev, [newCatName.trim()]: NOTE_COLORS[Object.keys(prev).length % NOTE_COLORS.length].value })) setNewCatName('') } const handleRemoveCategory = (cat) => { setLocalColors(prev => { const n = { ...prev }; delete n[cat]; return n }) } const handleRenameCategory = (oldName, newName) => { if (!newName.trim() || newName.trim() === oldName || localColors[newName.trim()]) return // Track rename for saving to DB later const originalName = Object.entries(renames).find(([, v]) => v === oldName)?.[0] || oldName setRenames(prev => ({ ...prev, [originalName]: newName.trim() })) setLocalColors(prev => { const n = {} for (const [k, v] of Object.entries(prev)) { n[k === oldName ? newName.trim() : k] = v } return n }) } const handleSave = async () => { // Apply renames to notes in DB for (const [oldName, newName] of Object.entries(renames)) { if (oldName !== newName) await onRenameCategory(oldName, newName) } await onSave(localColors) onClose() } // Merge existing categories from notes with saved colors const allCats = [...new Set([...categories, ...Object.keys(localColors)])] return ReactDOM.createPortal(
e.stopPropagation()}> {/* Header */}

{t('collab.notes.categorySettings') || 'Category Settings'}

{/* Categories list */}
{allCats.length === 0 && (

{t('collab.notes.noCategoriesYet') || 'No categories yet'}

)} {allCats.map(cat => (
{/* Color swatches */}
{NOTE_COLORS.map(c => (
{/* Category name — editable */} handleRenameCategory(cat, newName)} /> {/* Delete */}
))} {/* Add new */}
setNewCatName(e.target.value)} onKeyDown={e => e.key === 'Enter' && handleAddCategory()} placeholder={t('collab.notes.newCategory')} style={{ flex: 1, border: '1px solid var(--border-primary)', borderRadius: 10, padding: '8px 12px', fontSize: 13, background: 'var(--bg-input)', color: 'var(--text-primary)', fontFamily: 'inherit', outline: 'none', }} />
{/* Save */}
, document.body ) }