'use client' import React, { useState } from 'react' import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from '@/components/ui/card' import { Separator } from '@/components/ui/separator' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Checkbox } from '@/components/ui/checkbox' import { Label } from '@/components/ui/label' import { ShieldCheck, Building2, Calendar, Loader2, CheckCircle2, Pencil, Trash2, Plus, ChevronLeft, MessageSquare, FileText, Lock, Check, X, CreditCard, User, MapPin, Send, } from 'lucide-react' import * as Icons from 'lucide-react' import { Category, Product, EndCustomer, Profile } from '@/lib/types' interface StepSummaryProps { finalItemsToShow: any[] visibleCategories: Category[] products: Product[] oneTimeTotal: number monthlyTotal: number oneTimeNet: number oneTimeTax: number oneTimeGross: number monthlyNet: number monthlyTax: number monthlyGross: number updatePriceModifier: { label?: string } selectedEndCustomer: EndCustomer | null customerData: Partial lastLicenseDate: string handleSubmit: () => Promise isSubmitting: boolean initialOrder: any prevStep: () => void linkedFeeProducts?: Product[] orderNotes: string setOrderNotes: (notes: string) => void onEditBasketItem?: (idx: number) => void onAddNewBasketItem?: () => void onDeleteBasketItem?: (idx: number) => void } function CategoryIcon({ icon, className }: { icon?: string | null; className?: string }) { const LucideIcon = icon ? (Icons as any)[icon] : null if (!LucideIcon) return return } export function StepSummary({ finalItemsToShow, visibleCategories, products, oneTimeTotal, monthlyTotal, oneTimeNet, oneTimeTax, oneTimeGross, monthlyNet, monthlyTax, monthlyGross, updatePriceModifier, selectedEndCustomer, customerData, lastLicenseDate, handleSubmit, isSubmitting, initialOrder, prevStep, linkedFeeProducts = [], orderNotes, setOrderNotes, onEditBasketItem, onAddNewBasketItem, onDeleteBasketItem, }: StepSummaryProps) { const [confirmDeleteIdx, setConfirmDeleteIdx] = useState(null) const [acceptedTerms, setAcceptedTerms] = useState(false) const [showConfirmModal, setShowConfirmModal] = useState(false) const fmt = (val: number) => new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(val) const totalPositionsCount = finalItemsToShow.length const primaryInterval = finalItemsToShow[0]?.billingInterval || 'monthly' return ( {/* ─── 1. FIXED HEADER (shrink-0) ─── */}
Anfrage prüfen & absenden Überprüfen Sie alle konfigurierten Kassen, Positionen und Konditionen vor der Freigabe.
Schritt 4 von 4
{/* ─── 2. SCROLLABLE MIDDLE (flex-1 min-h-0 overflow-y-auto) ─── */}
{/* ─── LINKES RASTER (lg:col-span-7) – Auftragsübersicht & Kassen ─── */}
{/* Kopf-Card: Endkunde & Abrechnungsmodell */}
Kunde & Abrechnung
{primaryInterval === 'one_time' ? 'Einmalkauf' : 'Monatliches Abo'} {lastLicenseDate && ( Stichtag: {new Date(lastLicenseDate).toLocaleDateString('de-DE')} )}
{selectedEndCustomer ? (

{selectedEndCustomer.company_name}

{(selectedEndCustomer.first_name || selectedEndCustomer.last_name) && ( {[selectedEndCustomer.first_name, selectedEndCustomer.last_name].filter(Boolean).join(' ')} )} {(selectedEndCustomer.street || selectedEndCustomer.zip || selectedEndCustomer.city) && ( {[selectedEndCustomer.street, [selectedEndCustomer.zip, selectedEndCustomer.city].filter(Boolean).join(' ')].filter(Boolean).join(', ')} )} {selectedEndCustomer.vat_id && ( USt-IdNr: {selectedEndCustomer.vat_id} )}
) : (

Kein Endkunde zugewiesen (Partner-Bestellung).

)}
{/* Kassenliste */}

Enthaltene Kassen ({finalItemsToShow.length})

{onAddNewBasketItem && ( )}
{finalItemsToShow.length === 0 ? (

Keine Kassen in der Aufstellung vorhanden.

) : ( finalItemsToShow.map((item, itemIdx) => (
{/* Kassen Header Bar */}
{item.deviceName || `Kasse ${itemIdx + 1}`} {itemIdx > 0 && ( Kasse 2+ )} {item.licenseNumber && ( ({item.licenseNumber}) )}
{item.billingInterval === 'one_time' ? 'Kauf' : 'Abo'} {onEditBasketItem && ( )} {onDeleteBasketItem && ( )}
{/* Enthaltene Produkte & Module */}
{visibleCategories.map((cat) => { const sel = item.selections[cat.id] const selectedProds: Product[] = [] if (cat.allow_multiselect && sel?.productIds) { sel.productIds.forEach((pId: string) => { const p = products.find((prod) => prod.id === pId) if (p) selectedProds.push(p) }) } else if (sel?.productId) { const p = products.find((prod) => prod.id === sel.productId) if (p) selectedProds.push(p) } if (selectedProds.length === 0) return null const sortedProds = [...selectedProds].sort((a, b) => a.base_price - b.base_price) const freeLimit = cat.allow_multiselect ? cat.free_items_limit : 0 return (
{cat.name}: {sortedProds.map((prod, idx) => { const isFree = idx < freeLimit const isAbo = item.billingInterval === 'monthly' const displayPrice = isFree ? 0 : isAbo ? ((prod as any).monthly_price ?? prod.base_price) : prod.base_price return (
{prod.name} {isFree && ( Inklusive )} {isFree ? '0,00 €' : fmt(displayPrice)}
) })} {/* Selected Module Chips */} {sel?.moduleIds && sel.moduleIds.length > 0 && (
{sel.moduleIds.map((mId: string) => { let modObj: any = null products.forEach((p) => { const found = p.modules?.find((m) => m.id === mId) if (found) modObj = found }) if (!modObj) return null const isAbo = item.billingInterval === 'monthly' const qty = item.moduleQuantities?.[mId] || 1 const unitPrice = isAbo ? (modObj.monthly_price ?? modObj.price) : modObj.price const totalPrice = unitPrice * qty return (
+ {modObj.name} {qty > 1 ? `(${qty}x)` : ''} {fmt(totalPrice)}
) })}
)}
) })}
)) )} {/* Service- & Zusatz-Positionen */} {linkedFeeProducts.length > 0 && (
Service & Gebühren: {linkedFeeProducts.map((fp) => (
{fp.name} {fmt(fp.base_price)}
))}
)}
{/* ─── RECHTES RASTER (lg:col-span-5) – Notizen, Bedingungen & Summen ─── */}
{/* Glassmorphism Preiskalkulation */}

Gesamte Preiskalkulation

{oneTimeTotal > 0 && (
Einmalig (netto): {fmt(oneTimeNet)}
zzgl. 19% MwSt.: {fmt(oneTimeTax)}
{updatePriceModifier?.label && (
{updatePriceModifier.label}
)}
Einmalig gesamt (brutto): {fmt(oneTimeGross)}
)} {monthlyTotal > 0 && (
0 ? 'pt-3 border-t border-white/10' : ''}`}>
Monatlich (netto): {fmt(monthlyNet)} / mtl.
zzgl. 19% MwSt.: {fmt(monthlyTax)} / mtl.
Monatlich gesamt (brutto): {fmt(monthlyGross)} / mtl.
)}
{/* Bestellnotizen */}