"use client"; import { Trash2 } from "lucide-react"; import { toast } from "sonner"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Skeleton } from "@/components/ui/skeleton"; import { useCorpus, useDeleteCorpusEntry, type CorpusDecision } from "@/lib/api/training"; /* * Corpus tab: table of all decisions currently in the style corpus, with a * single destructive action (remove from corpus). Uses browser confirm() for * the confirmation — a full shadcn AlertDialog would be overkill for an * admin-only destructive action with a server-side safety net. */ function formatChars(n: number) { return `${(n / 1000).toFixed(1)}K`; } function formatDate(iso: string) { if (!iso) return "—"; try { return new Date(iso).toLocaleDateString("he-IL"); } catch { return iso; } } function Row({ item }: { item: CorpusDecision }) { const del = useDeleteCorpusEntry(); const onDelete = async () => { if (!window.confirm(`למחוק את החלטה ${item.decision_number} מהקורפוס?`)) return; try { await del.mutateAsync(item.id); toast.success("נמחק מהקורפוס"); } catch (e) { toast.error(e instanceof Error ? e.message : "שגיאה במחיקה"); } }; return ( {item.decision_number || "—"} {formatDate(item.decision_date)} {item.subject_categories.length === 0 ? ( ) : (
{item.subject_categories.map((s) => ( {s} ))}
)}
{formatChars(item.chars)} {formatDate(item.created_at)}
); } export function CorpusPanel() { const { data, isPending, error } = useCorpus(); if (error) { return (
{error.message}
); } return (
מס׳ החלטה תאריך נושאים תווים נוסף בתאריך {isPending ? ( [...Array(4)].map((_, i) => ( {[...Array(6)].map((_, j) => ( ))} )) ) : data?.length === 0 ? ( הקורפוס ריק ) : ( data?.map((item) => ) )}
); }