"use client"; import { use, useState } from "react"; import Link from "next/link"; import { Pencil, Check, X, Share2 } from "lucide-react"; import { toast } from "sonner"; import { AppShell } from "@/components/app-shell"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Skeleton } from "@/components/ui/skeleton"; import { Textarea } from "@/components/ui/textarea"; import { usePrecedent, useUpdatePrecedent, type Precedent, } from "@/lib/api/precedent-library"; import { PrecedentEditSheet } from "@/components/precedents/precedent-edit-sheet"; import { FormattedCitation, CitationCopyButton, } from "@/components/precedents/formatted-citation"; import { ExtractedHalachotSection } from "@/components/precedents/extracted-halachot"; import { RelatedCasesSection } from "@/components/precedents/link-related-dialog"; const PRACTICE_AREA_LABELS: Record = { rishuy_uvniya: "רישוי ובנייה", betterment_levy: "היטל השבחה", compensation_197: "פיצויים (197)", }; const SOURCE_TYPE_LABELS: Record = { court_ruling: "פסק דין", appeals_committee: "ועדת ערר", }; /** label/value pair in the parchment meta-band (mockup 08 `.mb`). */ function MetaItem({ label, children }: { label: string; children: React.ReactNode }) { return (
{label} {children}
); } /* Next 16 breaking change: route params are now a Promise. * The `use()` hook unwraps them inside a client component. */ export default function PrecedentDetailPage({ params, }: { params: Promise<{ id: string }>; }) { const { id } = use(params); const [editing, setEditing] = useState(false); const { data, isPending, error } = usePrecedent(id); const update = useUpdatePrecedent(); const [editingCitation, setEditingCitation] = useState(false); const [citationDraft, setCitationDraft] = useState(""); if (error) { return (

שגיאה בטעינת הפסיקה

{error.message}

); } if (isPending || !data) { return (
{[...Array(3)].map((_, i) => )}
); } const date = data.date ? data.date.slice(0, 10) : null; return (
{/* ── parchment header band (mockup 08 `.band`) — breaks out to the AppShell
edges (px-10 py-10) for a full-width band. ──── */}

{data.case_name || "—"}

{data.case_number}
{/* citation (unified Israeli citation rules) — chair-editable */}
{ setCitationDraft(data.citation_formatted ?? ""); setEditingCitation(true); }} onCancel={() => setEditingCitation(false)} onChange={setCitationDraft} onSave={async () => { try { await update.mutateAsync({ id, patch: { citation_formatted: citationDraft.trim() }, }); toast.success("מראה מקום עודכן"); setEditingCitation(false); } catch (e) { toast.error(e instanceof Error ? e.message : "שמירה נכשלה"); } }} saving={update.isPending} />
{/* meta-band — label/value pairs + chips (mockup 08 `.metaband`) */}
{data.court ? {data.court} : null} {date ? ( {date} ) : null} {data.practice_area ? ( {PRACTICE_AREA_LABELS[data.practice_area] ?? data.practice_area} ) : null} {data.source_type ? ( {SOURCE_TYPE_LABELS[data.source_type] ?? data.source_type} ) : null} {data.precedent_level ? ( {data.precedent_level} ) : null} {data.is_binding ? ( מחייב ) : null}
{data.subject_tags?.length ? (
{data.subject_tags.map((t) => ( {t} ))}
) : null}
{/* ── two-column body (mockup 08 `.wrap` grid) ────────────────── */}
{/* main column */}
{data.summary ? (

{data.summary}

) : null} {data.headnote ? (

{data.headnote}

) : null} {(data as { key_quote?: string }).key_quote ? (
{(data as { key_quote?: string }).key_quote}
) : null}
{/* side rail — citations + corroboration */}
setEditing(open)} />
); } /** main-column card with a navy heading + optional provenance pill * ("מולא ע״י Opus", mockup 08 `.prov`). */ function DetailCard({ title, prov, children, }: { title: string; prov?: "opus"; children: React.ReactNode; }) { return (

{title} {prov === "opus" ? ( מולא ע״י Opus ) : null}

{children}
); } function CitationBlock({ precedent, editing, draft, onStartEdit, onCancel, onChange, onSave, saving, }: { precedent: Precedent; editing: boolean; draft: string; onStartEdit: () => void; onCancel: () => void; onChange: (v: string) => void; onSave: () => void; saving: boolean; }) { const citation = (precedent.citation_formatted ?? "").trim(); if (editing) { return (
עריכת מראה מקום הקף את שמות הצדדים בכפול-כוכבית **שם** להדגשה