"use client";
import { useState } from "react";
import { Check, X, Edit2, AlertTriangle, Plus, GitMerge, Save } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Skeleton } from "@/components/ui/skeleton";
import {
usePlansPending, usePlanDuplicates, useUpsertPlan, useUpdatePlan,
useReviewPlan, useMergePlans, type Plan, type PlanEdit,
} from "@/lib/api/plans";
/* Strip bidi marks (mirror of the halacha panel's cleanCitation). */
function clean(s: string | null | undefined): string {
if (!s) return "—";
return s.replace(/[--]/g, "").trim();
}
function fmtDate(iso: string | null | undefined): string {
if (!iso) return "—";
const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(iso);
if (!m) return iso;
return `${Number(m[3])}.${Number(m[2])}.${m[1]}`;
}
type EditForm = {
plan_number: string;
display_name: string;
plan_type: string;
gazette_date: string;
yalkut_number: string;
purpose: string;
};
const BLANK: EditForm = {
plan_number: "", display_name: "", plan_type: "",
gazette_date: "", yalkut_number: "", purpose: "",
};
function toForm(p: Plan): EditForm {
return {
plan_number: p.plan_number,
display_name: p.display_name,
plan_type: p.plan_type,
gazette_date: p.gazette_date ?? "",
yalkut_number: p.yalkut_number,
purpose: p.purpose,
};
}
/* Client-side mirror of db.format_plan_citation — deterministic preview so the
* chair sees exactly what block-tet will cite (validity is never free-typed). */
function previewCitation(f: EditForm): string {
const name = f.display_name.trim() || f.plan_number.trim();
if (!name) return "—";
let s = name;
const d = fmtDate(f.gazette_date);
if (d !== "—") {
s = `${name} פורסמה למתן תוקף ברשומות ביום ${d}`;
if (f.yalkut_number.trim()) s += `, י"פ ${f.yalkut_number.trim()}`;
}
if (f.purpose.trim()) s += ` — ${f.purpose.trim()}`;
return s.endsWith(".") ? s : s + ".";
}
// ─────────────────────────────────────────────────────────────────────────────
export function PlansReviewPanel() {
const { data, isLoading, isError } = usePlansPending();
const [adding, setAdding] = useState(false);
if (isLoading) {
return (
{[0, 1, 2].map((i) => )}
);
}
if (isError) {
return
שגיאה בטעינת תור-התכניות.
;
}
const plans = data?.items ?? [];
return (
מרשם-התכניות: זהות + תוקף קנוניים של כל תב"ע, בשימוש חוזר בין תיקים.
רק תכנית מאושרת מצוטטת בבלוק ט; התוקף נכתב בנוסח אחיד{" "}
דטרמיניסטי —
תאריך-הרשומות ומס' הילקוט לעולם אינם מומצאים.