"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"; function formatDate(iso: string | null) { if (!iso) return "—"; try { return new Date(iso).toLocaleDateString("he-IL"); } catch { return iso; } } function HalachaCard({ hit }: { hit: Extract }) { return (
הלכה {hit.case_number} {hit.court && · {hit.court}} {hit.decision_date && · {formatDate(hit.decision_date)}} {hit.precedent_level && · {hit.precedent_level}} {/* PRE-3/PRE-5 (INV-IA5): the derived authority (binding/persuasive) rides on the wire but was dropped here — render it as in the review tab so search shows the same provenance everywhere. */} דירוג {hit.score.toFixed(2)}

{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.court}} {hit.decision_date && · {formatDate(hit.decision_date)}} · {hit.section_type} דירוג {hit.score.toFixed(2)}

{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 (
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" ? ( ) : ( ), )}
)}
); }