"use client"; import { useState } from "react"; import Link from "next/link"; import { useSearchParams } from "next/navigation"; import { PolicyForm } from "@/components/PolicyForm"; import { PolicyOcrIntake } from "@/components/PolicyOcrIntake"; import { useCan } from "@/lib/abilities"; /** * Policy intake — mirror of `Captura.tsx` (statement OCR side): one screen, * two ways in: * * - **manual** — `PolicyForm` keys every field by hand. * - **auto** — `PolicyOcrIntake` uploads a GMX or A.N.A. PDF, OCR proposes the * policy, a human still confirms. * * Both end at the same place (a `Policy` row on a customer's file) so they * live as two modes of one screen rather than two menu entries — exactly the * same shape Captura uses for `ManualCheckCapture` vs `StatementIntake`. * * `/polizas/nuevo` opens manual, `/polizas/captura` opens auto; both render * this component so the tab toggle works either way and an old bookmark * still lands on the right tab. */ export type PolicyCaptureMode = "manual" | "auto"; const MODE_HINT: Record = { manual: "Captura cada campo a mano. Use esta opción cuando la póliza llega en papel, en un correo sin PDF legible, o cuando hay que revisar cada dato.", auto: "Suelte el PDF descargado del portal de GMX o de A.N.A. y el sistema propondrá los campos. Nada se registra sin tu confirmación.", }; export function PolicyCaptura({ initialMode = "manual" }: { initialMode?: PolicyCaptureMode }) { const canCreate = useCan("policy:create"); const canIngest = useCan("policy:ingest"); // `/clientes/[id]` deep-links into /polizas/nuevo with the customer // pre-picked so staff can fill the rest without retyping. The OCR pane // ignores these — there's no customer to lock in until the batch is // confirmed. const params = useSearchParams(); const fixedCustomerId = params.get("customerId") ?? undefined; const fixedCustomerName = params.get("customerName") ?? undefined; // One user can land on either mode. The tab strip only renders when both // abilities are held — a STAFF with only policy:ingest (no create) still // sees the screen but only the OCR tab is offered. const modes: { key: PolicyCaptureMode; label: string }[] = [ ...(canCreate ? [{ key: "manual" as const, label: "Captura manual" }] : []), ...(canIngest ? [{ key: "auto" as const, label: "Captura automática (OCR)" }] : []), ]; const [mode, setMode] = useState( modes.some((m) => m.key === initialMode) ? initialMode : (modes[0]?.key ?? "manual"), ); if (modes.length === 0) { return (
No tienes permiso para crear ni capturar pólizas.
); } return ( <>
← Pólizas

Nueva póliza

{MODE_HINT[mode]}

{modes.length > 1 && (
{modes.map((m) => ( ))}
)} {mode === "manual" ? ( ) : ( )} ); } function ManualPane({ fixedCustomerId, fixedCustomerName, }: { fixedCustomerId?: string; fixedCustomerName?: string; }) { const allowed = useCan("policy:create"); if (!allowed) { return (
No tiene permisos para crear pólizas.
); } return ( ); }