"use client"; import { AlertTriangle, Check, Database, X } from "lucide-react"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import type { ImportPreviewData } from "@/lib/ai-chat"; import { commitImport } from "@/lib/ai-settings"; import { notify } from "@/lib/toast"; type Status = "pending" | "committing" | "done" | "rejected"; // The human approval gate for the migration import. The agent proposes records // (dry run, nothing written); the clinician reviews counts + issues here and // must approve before anything is inserted via POST /api/ai/import. export function ImportPreviewCard({ data }: { data: ImportPreviewData }) { const { t } = useTranslation(); const [status, setStatus] = useState("pending"); const [result, setResult] = useState<{ created: number; failed: number } | null>( null, ); const approve = async () => { setStatus("committing"); try { const res = await commitImport(data.valid); setResult({ created: res.created.length, failed: res.failed.length }); setStatus("done"); notify.success( t("chat.importCard.importedTitle"), t("chat.importCard.importedBody", { count: res.created.length }), ); } catch { setStatus("pending"); notify.error( t("chat.importCard.failedTitle"), t("chat.importCard.failedBody"), ); } }; return (
{t("chat.importCard.title")}
{t("chat.importCard.ready")}{" "} {data.valid.length} {data.invalid.length > 0 ? ( {t("chat.importCard.skipped")}{" "} {data.invalid.length} ) : null} {t("chat.importCard.total")}{" "} {data.total}
{data.invalid.length > 0 ? ( ) : null} {status === "done" && result ? (

{t("chat.importCard.importedBody", { count: result.created })} {result.failed > 0 ? ` ยท ${t("chat.importCard.failedCount", { count: result.failed })}` : ""}

) : status === "rejected" ? (

{t("chat.importCard.rejectedNote")}

) : (
)}
); }