"use client"; import { useState, useEffect } from "react"; import { Card } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Textarea } from "@/components/ui/textarea"; import { Markdown } from "@/components/ui/markdown"; import { useMethodology, useUpdateMethodology, useResetMethodology, } from "@/lib/api/methodology"; import { toast } from "sonner"; import { Save, RotateCcw, Eye, EyeOff, Loader2 } from "lucide-react"; const CHECKLIST_LABELS: Record = { licensing_substantive: "ערר רישוי מהותי", licensing_threshold: "ערר רישוי סף/סמכות", licensing_property: "ערר רישוי קנייני", tama38: "תמ\"א 38", betterment_levy: "היטל השבחה", }; const CHECKLIST_ORDER = [ "licensing_substantive", "licensing_threshold", "licensing_property", "tama38", "betterment_levy", ]; // MET-6 (INV-IA6/INV-IA5): which case selects each checklist — mirrors the // server's get_content_checklist() routing (lessons.py:580-622) so the chair // sees *when* a checklist is consumed, not five unlabelled types. const CHECKLIST_APPLIES: Record = { licensing_substantive: "ברירת-מחדל — כל ערר רישוי שאינו נופל לקטגוריה אחרת", licensing_threshold: "עררי רישוי בנושא סמכות / סף / סילוק-על-הסף / זכות-ערר", licensing_property: "עררי רישוי בנושא תימוכין קנייניים / בעלות / הסכמת-דיירים", tama38: 'עררים בנושא תמ"א 38 / חיזוק', betterment_levy: "תיקי היטל השבחה (8xxx)", }; type ChecklistItem = { key: string; label: string; original: string; draft: string; isOverride: boolean; dirty: boolean; }; export function ContentChecklistsPanel() { const { data, isLoading } = useMethodology("content_checklists"); const update = useUpdateMethodology("content_checklists"); const reset = useResetMethodology("content_checklists"); const [items, setItems] = useState([]); const [active, setActive] = useState(CHECKLIST_ORDER[0]); const [preview, setPreview] = useState(false); useEffect(() => { if (!data?.items) return; // eslint-disable-next-line react-hooks/set-state-in-effect -- sync from server setItems( CHECKLIST_ORDER .filter((k) => k in data.items) .map((key) => ({ key, label: CHECKLIST_LABELS[key] ?? key, original: data.items[key].value, draft: data.items[key].value, isOverride: data.items[key].is_override, dirty: false, })), ); }, [data]); const current = items.find((i) => i.key === active); const updateDraft = (text: string) => { setItems((prev) => prev.map((i) => i.key === active ? { ...i, draft: text, dirty: text !== i.original } : i, ), ); }; const handleSave = () => { if (!current) return; update.mutate( { key: current.key, value: current.draft }, { onSuccess: () => toast.success(`${current.label} נשמר`), onError: () => toast.error("שגיאה בשמירה"), }, ); }; const handleReset = () => { if (!current) return; reset.mutate(current.key, { onSuccess: () => toast.success(`${current.label} אופס`), onError: () => toast.error("שגיאה באיפוס"), }); }; if (isLoading) { return (
טוען...
); } const itemCount = current ? current.draft.split("\n").filter((l) => /^\s*-\s*\[/.test(l)).length : 0; return (
{/* Type buttons — gold active (mockup 13) */}
{items.map((item) => { const isActive = active === item.key; return ( ); })}
{/* "חל על:" explainer band — gold-wash (mockup 13) */} {current && CHECKLIST_APPLIES[current.key] && (
חל על: {CHECKLIST_APPLIES[current.key]}
)} {/* Editor — framed card with header chip + parchment editor + footer */} {current && (

צ׳קליסט תוכן — {current.label}

{current.isOverride ? "מותאם" : "ידני"}
{preview ? (
) : (