"use client"; import { useState } from "react"; import { Search } from "lucide-react"; import { Input } from "@/components/ui/input"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { useLibrarySearch, type PracticeArea, type SearchHit, } from "@/lib/api/precedent-library"; import { PRACTICE_AREAS, PRECEDENT_LEVELS } from "./practice-area"; import { AuthorityBadge } from "./halacha-meta"; import { formatDateShort as formatDate } from "@/lib/format-date"; /** Score chip — boxed, gold-deep, tabular (mockup 07 `.score`). Sits at the * end of the meta row via `ms-auto`. White fill on gold-wash halacha cards. */ function ScoreChip({ score, onWash }: { score: number; onWash?: boolean }) { return ( דירוג {score.toFixed(2)} ); } function HalachaCard({ hit }: { hit: Extract }) { return (
הלכה {hit.case_number} {(hit.court || hit.decision_date || hit.precedent_level) && ( {hit.court ? `· ${hit.court}` : ""} {hit.decision_date ? ` · ${formatDate(hit.decision_date)}` : ""} {hit.precedent_level ? ` · ${hit.precedent_level}` : ""} )} {/* PRE-3/PRE-5 (INV-IA5): derived authority (binding/persuasive) rides on the wire — render the pill as in the review tab. */}

{hit.rule_statement}

“{hit.supporting_quote}” {hit.page_reference && ( ({hit.page_reference}) )}
{hit.subject_tags?.length > 0 && (
{hit.subject_tags.map((t) => ( {t} ))}
)}
); } function PassageCard({ hit }: { hit: Extract }) { return (
קטע {hit.case_number} {(hit.court || hit.decision_date) && ( {hit.court ? `· ${hit.court}` : ""} {hit.decision_date ? ` · ${formatDate(hit.decision_date)}` : ""} )} {hit.section_type}

{hit.content.slice(0, 600)} {hit.content.length > 600 && }

); } export function LibrarySearchPanel() { const [draft, setDraft] = useState(""); const [query, setQuery] = useState(""); const [practiceArea, setPracticeArea] = useState(""); const [precedentLevel, setPrecedentLevel] = useState(""); const [includeHalachot, setIncludeHalachot] = useState(true); const { data, isFetching, error } = useLibrarySearch(query, { practiceArea: practiceArea || undefined, precedentLevel: precedentLevel || undefined, includeHalachot, limit: 20, }); const onSubmit = (e: React.FormEvent) => { e.preventDefault(); setQuery(draft.trim()); }; return (
{/* search panel — boxed surface with query row + two-up filter row + controls strip (checkbox start, gold CTA end) per mockup 07. */}
setDraft(e.target.value)} placeholder="השבחה אובייקטיבית" dir="rtl" />
{!query.trim() ? (
הקלד שאילתא כדי לחפש בקורפוס. החיפוש סמנטי — לא טקסטואלי.
) : error ? (
{error.message}
) : isFetching ? (
{[...Array(3)].map((_, i) => )}
) : !data?.items.length ? (
לא נמצאו תוצאות. נסה ניסוח אחר או הסר פילטרים.
) : (

תוצאות הלכות מאושרות בלבד · {data.count} תוצאות

{data.items.map((hit, i) => hit.type === "halacha" ? ( ) : ( ), )}
)}
); }