'use client'; import { PointsEntry } from '@/lib/schemas/leaderboard'; interface PointsTableEditorProps { pointsTable: PointsEntry[]; onChange: (pointsTable: PointsEntry[]) => void; } export function PointsTableEditor({ pointsTable, onChange }: PointsTableEditorProps) { const update = (index: number, patch: Partial) => { onChange(pointsTable.map((e, i) => (i === index ? { ...e, ...patch } : e))); }; const remove = (index: number) => { onChange(pointsTable.filter((_, i) => i !== index)); }; const add = () => { const pos = pointsTable.length + 1; onChange([ ...pointsTable, { id: crypto.randomUUID(), points: 0, label: `P${pos}`, color: '#374151', textColor: '#ffffff', priority: pos } ]); }; return (
{pointsTable.map((entry, i) => (
update(i, { label: e.target.value })} className="w-20 rounded bg-gray-600 px-2 py-1 text-sm text-white" />
update(i, { points: parseInt(e.target.value) || 0 })} className="w-20 rounded bg-gray-600 px-2 py-1 text-sm text-white" />
update(i, { priority: parseInt(e.target.value) || 0 })} className="w-20 rounded bg-gray-600 px-2 py-1 text-sm text-white" />
update(i, { color: e.target.value })} className="h-8 w-8 cursor-pointer rounded border-0 bg-transparent" /> { if (/^#[0-9a-fA-F]{6}$/.test(e.target.value)) update(i, { color: e.target.value }); }} className="w-24 rounded bg-gray-600 px-2 py-1 font-mono text-sm text-white" />
update(i, { textColor: e.target.value })} className="h-8 w-8 cursor-pointer rounded border-0 bg-transparent" /> { if (/^#[0-9a-fA-F]{6}$/.test(e.target.value)) update(i, { textColor: e.target.value }); }} className="w-24 rounded bg-gray-600 px-2 py-1 font-mono text-sm text-white" />
{entry.label}
))}
); }