"use client"; import { useState } from "react"; import { useConfiguratorStore } from "@/lib/store"; import { sendQuoteAction } from "@/actions/send-quote"; import { Button } from "@/components/ui/button"; import { Send, Check, Loader2, CheckCircle2, AlertCircle } from "lucide-react"; // ============================================ // LABEL MAPS // ============================================ const DOOR_TYPE_LABELS: Record = { taats: "Taatsdeur", scharnier: "Scharnierdeur", paneel: "Vast Paneel", }; const CONFIG_LABELS: Record = { enkele: "Enkele deur", dubbele: "Dubbele deur", }; const SIDE_PANEL_LABELS: Record = { geen: "Geen", links: "Links", rechts: "Rechts", beide: "Beide zijden", }; const FINISH_LABELS: Record = { zwart: "Mat Zwart", brons: "Brons", grijs: "Antraciet", goud: "Goud", beige: "Beige", ral: "RAL Kleur", }; const GLASS_COLOR_LABELS: Record = { helder: "Helder", grijs: "Rookglas", brons: "Bronsglas", "mat-blank": "Mat Blank", "mat-brons": "Mat Brons", "mat-zwart": "Mat Zwart", }; const HANDLE_LABELS: Record = { beugelgreep: "Beugelgreep", hoekgreep: "Hoekgreep", maangreep: "Maangreep", ovaalgreep: "Ovaalgreep", klink: "Deurklink", "u-greep": "U-Greep", geen: "Geen greep", }; const PATTERN_LABELS: Record = { standard: "Standaard", "dt9-rounded": "DT9 Afgerond", "dt10-ushape": "DT10 U-vorm", }; function formatPrice(amount: number): string { return new Intl.NumberFormat("nl-NL", { style: "currency", currency: "EUR", minimumFractionDigits: 0, maximumFractionDigits: 0, }).format(amount); } // ============================================ // COMPONENTS // ============================================ function SummaryRow({ label, value, highlight }: { label: string; value: string; highlight?: boolean }) { return (
{label} {value}
); } function SummarySection({ title, children }: { title: string; children: React.ReactNode }) { return (

{title}

{children}
); } function PriceRow({ label, amount, bold }: { label: string; amount: number; bold?: boolean }) { if (amount === 0) return null; return (
{label} {formatPrice(amount)}
); } // ============================================ // MAIN COMPONENT // ============================================ export function StepSummary() { const store = useConfiguratorStore(); const [status, setStatus] = useState<"idle" | "loading" | "success" | "error">("idle"); const [errorMsg, setErrorMsg] = useState(""); const { doorType, gridType, doorConfig, sidePanel, width, height, doorLeafWidth, finish, glassColor, handle, frameSize, glassPattern, extraOptions, name, email, phone, note, priceBreakdown, screenshotDataUrl, } = store; const canSubmit = name.length >= 2 && email.includes("@") && phone.length >= 10; async function handleSubmit() { if (!canSubmit) return; setStatus("loading"); setErrorMsg(""); const result = await sendQuoteAction({ doorType, gridType, doorConfig, sidePanel, width, height, doorLeafWidth, finish, glassColor, handle, frameSize, glassPattern, extraOptions, name, email, phone, note, totalPrice: priceBreakdown.totalPrice, steelCost: priceBreakdown.steelCost, glassCost: priceBreakdown.glassCost, baseFee: priceBreakdown.baseFee, mechanismSurcharge: priceBreakdown.mechanismSurcharge, sidePanelSurcharge: priceBreakdown.sidePanelSurcharge, handleCost: priceBreakdown.handleCost, finishSurcharge: priceBreakdown.finishSurcharge, screenshotDataUrl, }); if (result.success) { setStatus("success"); } else { setStatus("error"); setErrorMsg(result.error || "Onbekende fout"); } } if (status === "success") { return (

Aanvraag Verstuurd!

Bedankt {name}, uw offerte aanvraag is ontvangen.

We sturen een bevestiging naar {email}.

); } return (

Overzicht

Controleer uw configuratie en verstuur de aanvraag.

{/* Product Section */} {/* Dimensions Section */} {/* Style Section */} {/* Extra Options */} {extraOptions.length > 0 && ( {extraOptions.map((opt) => (
{opt}
))}
)} {/* Price Breakdown */}

Indicatieprijs

* Dit is een indicatieprijs. De definitieve prijs wordt bepaald na opmeting.

{/* Contact Summary */} {note && } {/* Validation Warning */} {!canSubmit && (
Vul eerst uw contactgegevens in (stap 5) om de aanvraag te versturen.
)} {/* Error Message */} {status === "error" && (
{errorMsg}
)} {/* Submit Button */}
); }