"use client"; import { use, useRef, useState } from "react"; import Link from "next/link"; import { AppShell } from "@/components/app-shell"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import { SubsectionCard } from "@/components/compose/subsection-card"; import { PrecedentsSection } from "@/components/compose/precedents-section"; import { Markdown } from "@/components/ui/markdown"; import { useCase } from "@/lib/api/cases"; import { useResearchAnalysis } from "@/lib/api/research"; import { useCasePrecedents } from "@/lib/api/precedents"; function ProseSection({ title, content }: { title: string; content?: string }) { if (!content?.trim()) return null; return (

{title}

); } function AnalysisActions({ caseNumber, hasAnalysis, onUploaded, }: { caseNumber: string; hasAnalysis: boolean; onUploaded: () => void; }) { const fileRef = useRef(null); const [uploading, setUploading] = useState(false); const [uploadMsg, setUploadMsg] = useState<{ ok: boolean; text: string } | null>(null); async function handleUpload(file: File) { setUploading(true); setUploadMsg(null); try { const form = new FormData(); form.append("file", file); const res = await fetch(`/api/cases/${caseNumber}/research/analysis/upload`, { method: "PUT", body: form, }); const data = await res.json(); if (!res.ok) { setUploadMsg({ ok: false, text: data.detail || "שגיאה בהעלאה" }); return; } setUploadMsg({ ok: true, text: `הקובץ הועלה בהצלחה — ${data.sections.threshold_claims} טענות סף, ${data.sections.issues} סוגיות`, }); onUploaded(); } catch { setUploadMsg({ ok: false, text: "שגיאת רשת" }); } finally { setUploading(false); if (fileRef.current) fileRef.current.value = ""; } } return (
{uploadMsg && ( {uploadMsg.text} )} { const f = e.target.files?.[0]; if (f) handleUpload(f); }} /> {hasAnalysis && ( )} {hasAnalysis && ( )}
); } export default function ComposePage({ params, }: { params: Promise<{ caseNumber: string }>; }) { const { caseNumber } = use(params); const caseQuery = useCase(caseNumber); const analysis = useResearchAnalysis(caseNumber); const precedentsQuery = useCasePrecedents(caseNumber); /* Partition the flat list into scopes so each child renders its own slice * without re-fetching. Done once at the page level. */ const allPrecedents = precedentsQuery.data ?? []; const caseLevelPrecedents = allPrecedents.filter((p) => p.section_id === null); const precedentsBySection = new Map(); for (const p of allPrecedents) { if (p.section_id) { const existing = precedentsBySection.get(p.section_id) ?? []; existing.push(p); precedentsBySection.set(p.section_id, existing); } } const practiceArea = caseQuery.data?.practice_area ?? null; const isNotFound = analysis.error instanceof Error && /404|לא נמצא|טרם בוצע/.test(analysis.error.message); return (
{/* Header strip */}

ניתוח משפטי וכתיבת עמדה

{caseQuery.data?.title && (

{caseQuery.data.title}

)}
analysis.refetch()} />
{analysis.isPending ? ( ) : isNotFound ? (

טרם בוצע ניתוח משפטי לתיק זה

לאחר שקובץ analysis-and-research.md ייווצר, תוכלי לערוך כאן את עמדת הוועדה לכל טענת סף וסוגיה.

) : analysis.error ? (

{analysis.error.message}

) : analysis.data ? (
{/* Case-level general precedents */}

פסיקה כללית לדיון

ציטוטים התומכים בעמדה באופן רוחבי — ישולבו בפתיחת בלוק י (דיון).

{/* Threshold claims */} {analysis.data.threshold_claims && analysis.data.threshold_claims.length > 0 && (

טענות סף

{analysis.data.threshold_claims.length}
{analysis.data.threshold_claims.map((tc) => ( ))}
)} {/* Issues */} {analysis.data.issues && analysis.data.issues.length > 0 && (

סוגיות להכרעה

{analysis.data.issues.length}
{analysis.data.issues.map((iss) => ( ))}
)} {(!analysis.data.threshold_claims?.length && !analysis.data.issues?.length) && ( לא נמצאו טענות סף או סוגיות בניתוח זה. )} {/* Background prose — moved below the issues so it reads as supporting context after the chair has seen the main decision points, not as a wall of text beside them. */}

רקע לניתוח

{analysis.data.conclusions?.trim() && (

מסקנות

)}
) : null}
); }