'use client' import { useState } from 'react' import { Button } from './ui/button' import { Input } from './ui/input' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from './ui/dialog' import { Badge } from './ui/badge' import { Settings, Plus, Palette, Trash2, Tag } from 'lucide-react' import { LABEL_COLORS, LabelColorName } from '@/lib/types' import { cn } from '@/lib/utils' import { useLabels } from '@/context/LabelContext' export function LabelManagementDialog() { const { labels, loading, addLabel, updateLabel, deleteLabel } = useLabels() const [newLabel, setNewLabel] = useState('') const [editingColorId, setEditingColorId] = useState(null) const handleAddLabel = async () => { const trimmed = newLabel.trim() if (trimmed) { try { await addLabel(trimmed, 'gray') setNewLabel('') } catch (error) { console.error('Failed to add label:', error) } } } const handleDeleteLabel = async (id: string) => { if (confirm('Are you sure you want to delete this label?')) { try { await deleteLabel(id) } catch (error) { console.error('Failed to delete label:', error) } } } const handleChangeColor = async (id: string, color: LabelColorName) => { try { await updateLabel(id, { color }) setEditingColorId(null) } catch (error) { console.error('Failed to update label color:', error) } } return ( Edit Labels Create, edit colors, or delete labels.
{/* Add new label */}
setNewLabel(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') { e.preventDefault() handleAddLabel() } }} />
{/* List labels */}
{loading ? (

Loading...

) : labels.length === 0 ? (

No labels found.

) : ( labels.map((label) => { const colorClasses = LABEL_COLORS[label.color] const isEditing = editingColorId === label.id return (
{label.name} {/* Color Picker Popover */} {isEditing && (
{(Object.keys(LABEL_COLORS) as LabelColorName[]).map((color) => { const classes = LABEL_COLORS[color] return (
)}
) }) )}
) }