'use client'; import { useState } from 'react'; import { IconFolder, IconTrash, IconEdit, IconCheck, IconX, IconPlus } from '@tabler/icons-react'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Badge } from '@/components/ui/badge'; import type { Context, Column } from '@/lib/settings/types'; type ContextCardProps = { context: Context; onUpdate: (context: Context) => void; onDelete: () => void; }; const COLOR_OPTIONS = [ { value: 'bg-neutral-400', label: 'Gray' }, { value: 'bg-red-500', label: 'Red' }, { value: 'bg-orange-500', label: 'Orange' }, { value: 'bg-yellow-500', label: 'Yellow' }, { value: 'bg-green-500', label: 'Green' }, { value: 'bg-blue-500', label: 'Blue' }, { value: 'bg-indigo-500', label: 'Indigo' }, { value: 'bg-violet-500', label: 'Violet' }, { value: 'bg-cyan-500', label: 'Cyan' }, { value: 'bg-sky-500', label: 'Sky' }, ]; export function ContextCard({ context, onUpdate, onDelete }: ContextCardProps) { const [isEditing, setIsEditing] = useState(false); const [editedContext, setEditedContext] = useState(context); const handleSave = () => { onUpdate(editedContext); setIsEditing(false); }; const handleCancel = () => { setEditedContext(context); setIsEditing(false); }; const handleAddColumn = () => { setEditedContext({ ...editedContext, columns: [ ...editedContext.columns, { id: crypto.randomUUID(), title: '', color: 'bg-neutral-400' }, ], }); }; const handleRemoveColumn = (id: string) => { setEditedContext({ ...editedContext, columns: editedContext.columns.filter((c) => c.id !== id), }); }; const handleUpdateColumn = (id: string, field: 'title' | 'color' | 'id', value: string) => { setEditedContext({ ...editedContext, columns: editedContext.columns.map((c) => c.id === id ? { ...c, [field]: value } : c ), }); }; if (isEditing) { return (
setEditedContext({ ...editedContext, name: e.target.value })} />
{editedContext.columns.map((column, index) => (
handleUpdateColumn(column.id, 'title', e.target.value) } />
handleUpdateColumn(column.id, 'id', e.target.value) } />
))}
); } return ( setIsEditing(true)}>

{context.name}

{context.columns.map((column) => { // Map Tailwind bg colors to actual hex values const colorMap: Record = { 'bg-neutral-400': '#a3a3a3', 'bg-red-500': '#ef4444', 'bg-orange-500': '#f97316', 'bg-yellow-500': '#eab308', 'bg-green-500': '#22c55e', 'bg-blue-500': '#3b82f6', 'bg-indigo-500': '#6366f1', 'bg-violet-500': '#8b5cf6', 'bg-cyan-500': '#06b6d4', 'bg-sky-500': '#0ea5e9', }; return ( {column.title} ); })}
e.stopPropagation()}>
); }