"use client"; import Link from "next/link"; import { useEffect, useState } from "react"; import { OrderStepper } from "@/components/order-stepper"; import { useT } from "@/components/locale-provider"; import { useReveal } from "@/hooks/use-reveal"; import { formatSEK, computeEstimate, entityLabel, FREQUENCY_LABEL, type Estimate, type EntityType, type Frequency, } from "@/lib/data"; const FALLBACK: Estimate = computeEstimate({ markets: ["SE", "NO", "DK", "FI"], type: "Bolag", fieldIds: ["lei", "financials", "contact"], enrichmentIds: ["nace"], volume: 5000, frequency: "Engångs", confidence: 92, }); const TRUST: { title: { en: string; sv: string }; body: { en: string; sv: string } }[] = [ { title: { en: "Provenance per field", sv: "Härkomst per fält" }, body: { en: "Source, freshness, confidence.", sv: "Källa, färskhet, konfidens." }, }, { title: { en: "GDPR-native", sv: "GDPR-native" }, body: { en: "DPA and lawful basis per field.", sv: "DPA och laglig grund per fält." }, }, { title: { en: "You push your data", sv: "Du pushar din data" }, body: { en: "Read-only role. Time-boxed. Deleted afterwards.", sv: "Read-only roll. Tidsbegränsad. Raderad efteråt.", }, }, { title: { en: "Audit log", sv: "Revisionslogg" }, body: { en: "What. When. Why.", sv: "Vad. När. Varför." }, }, ]; const RECAP_LABELS: Record = { markets: { en: "Markets", sv: "Marknader" }, type: { en: "Type", sv: "Typ" }, volume: { en: "Volume", sv: "Volym" }, frequency: { en: "Frequency", sv: "Frekvens" }, }; export default function DepositPage() { const t = useT(); const [est, setEst] = useState(FALLBACK); const [recap, setRecap] = useState<{ markets: string; type: EntityType; volume: string; frequency: Frequency }>({ markets: "SE · NO · DK · FI", type: "Bolag", volume: "5 000", frequency: "Engångs", }); const [orderId, setOrderId] = useState(null); const [paying, setPaying] = useState(false); const [paymentError, setPaymentError] = useState(false); const reveal = useReveal(); useEffect(() => { try { const raw = sessionStorage.getItem("0pt-order"); if (raw) { const o = JSON.parse(raw); if (o.est) setEst(o.est); setRecap({ markets: (o.markets || []).join(" · "), type: (o.type as EntityType) || "Bolag", volume: new Intl.NumberFormat("sv-SE").format(o.volume || 0), frequency: (o.frequency as Frequency) || "Engångs", }); } } catch {} const oid = new URLSearchParams(window.location.search).get("order"); if (oid) { setOrderId(oid); fetch(`/api/orders/${oid}`) .then((r) => (r.ok ? r.json() : null)) .then((o) => { if (!o) return; setEst((prev) => ({ ...prev, price: Math.round((o.total_ore ?? 0) / 100) || prev.price, deposit: Math.round((o.deposit_ore ?? 0) / 100) || prev.deposit, remainder: Math.round((o.balance_ore ?? 0) / 100) || prev.remainder, })); const c = o.config || {}; setRecap({ markets: (c.markets || []).join(" · "), type: (c.type as EntityType) || "Bolag", volume: new Intl.NumberFormat("sv-SE").format(c.volume || 0), frequency: (c.frequency as Frequency) || "Engångs", }); }) .catch(() => {}); } }, []); async function pay() { if (paying) return; setPaying(true); setPaymentError(false); if (orderId) { try { const r = await fetch(`/api/payments/${orderId}/deposit`, { method: "POST" }); if (r.ok) { const body = await r.json() as { url?: string }; if (body.url) { window.location.href = body.url; return; } } } catch {} } // No Checkout URL means no payment. Keep the draft and let the customer // retry; never simulate a successful payment or redirect to a demo order. setPaymentError(true); setPaying(false); } return (
{/* header */}

{t({ en: "Step 2 — Deposit", sv: "Steg 2 — Förskott" })}

{t({ en: "Half now.", sv: "Halva nu." })}
{t({ en: "Half in escrow.", sv: "Halva i depå." })}

02
{/* split */}

{t({ en: "Payment structure", sv: "Betalningsupplägg" })}

50 / 50

{t({ en: "Now", sv: "Nu" })}

{formatSEK(est.deposit)}

{t({ en: "Starts the job. Today.", sv: "Startar jobbet. Idag." })}

{t({ en: "On approval", sv: "Vid godkänt" })}

{formatSEK(est.remainder)}

{t({ en: "Released from escrow.", sv: "Frigörs ur depå." })}

{t({ en: "The other half isn't touched until you click Approve.", sv: "Andra halvan rörs först när du tryckt Godkänn." })}

{/* trust */}

{t({ en: "Data & access", sv: "Data & åtkomst" })}

{TRUST.map((item, i) => (
{String(i + 1).padStart(2, "0")}
{t(item.title)}
{t(item.body)}
))}
{/* summary */}
); }