'use client' import React from 'react' import { Card, CardHeader, CardTitle, CardContent, CardFooter } from '@/components/ui/card' import { Label } from '@/components/ui/label' import { Input } from '@/components/ui/input' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { ChevronRight, ChevronLeft, AlertCircle, Check, ShoppingCart, Save, Plus, } from 'lucide-react' import { Category, Product, CategorySelection } from '@/lib/types' interface SummarySidebarProps { visibleCategories: Category[] selections: Record products: Product[] moduleQuantities: Record billingLabel: (interval: string) => string oneTimeTotal: number monthlyTotal: number oneTimeNet: number oneTimeTax: number oneTimeGross: number monthlyNet: number monthlyTax: number monthlyGross: number updatePriceModifier: { label?: string } allCategoriesFilled: boolean productValidationErrors: string[] editingIdx: number | null deviceName: string setDeviceName: (name: string) => void licenseNumber: string setLicenseNumber: (num: string) => void onSaveAndProceed: () => void isNextStepDisabled: boolean hasActiveSelection: boolean showValidationWarning?: boolean prevStep: () => void } export function SummarySidebar({ visibleCategories, selections, products, moduleQuantities, billingLabel, oneTimeTotal, monthlyTotal, oneTimeNet, oneTimeTax, oneTimeGross, monthlyNet, monthlyTax, monthlyGross, updatePriceModifier, allCategoriesFilled, productValidationErrors, editingIdx, deviceName, setDeviceName, licenseNumber, setLicenseNumber, onSaveAndProceed, isNextStepDisabled, prevStep, }: SummarySidebarProps) { const fmt = (val: number) => new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(val) const isEditing = editingIdx !== null const currentDeviceTitle = isEditing ? `Kasse ${editingIdx + 1}` : (deviceName.trim() || 'Neue Kasse') const isSaveDisabled = !allCategoriesFilled || productValidationErrors.length > 0 return ( {/* ─── 1. TOP HEADER (shrink-0) ─── */}
Kassen-Konfiguration {isEditing ? `Bearbeite #${editingIdx + 1}` : 'Neuer Eintrag'}
{/* ─── 2. SCROLLABLE MIDDLE (flex-1 min-h-0 overflow-y-auto) ─── */} {/* Aktuelle Kassen-Auswahl */}
Gewählte Positionen
{/* Selected Categories List */}
{visibleCategories.map(cat => { const sel = selections[cat.id] const selectedProds: Product[] = [] if (cat.allow_multiselect && sel?.productIds) { sel.productIds.forEach(pId => { 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 (
{cat.is_required ? ( ) : ( )} {cat.name}: {cat.is_required ? 'nicht gewählt (Pflicht)' : 'nicht gewählt (optional)'}
) 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 actualPrice = isFree ? 0 : prod.base_price return (
{prod.name} {isFree && (Inkl.)} {fmt(actualPrice)}
{sel.moduleIds.map(mId => { const mod = prod.modules?.find(m => m.id === mId) const qty = moduleQuantities[mId] || 1 return mod ? (
+ {mod.name} {mod.has_quantity ? `(x${qty})` : ''} {fmt(mod.price * qty)}
) : null })}
) })}
) })}
{/* Pricing Box */}
{oneTimeTotal > 0 && (
Kaufpreis Kasse (netto): {fmt(oneTimeNet)}
Kaufpreis Kasse (brutto): {fmt(oneTimeGross)}
)} {monthlyTotal > 0 && (
0 ? 'pt-2 border-t border-white/10' : ''}`}>
Mietpreis Kasse (netto): {fmt(monthlyNet)} / mtl.
Mietpreis Kasse (brutto): {fmt(monthlyGross)} / mtl.
)}
{/* Gerätename & Lizenznummer Eingabe */}

{isEditing ? `Kasse anpassen` : `Kassenbezeichnung`}

setDeviceName(e.target.value)} className="bg-white/5 border-white/10 text-white text-xs h-8 rounded-lg" />
setLicenseNumber(e.target.value)} className="bg-white/5 border-white/10 text-white text-xs h-8 rounded-lg font-mono uppercase" />
{/* ─── 3. FIXED BOTTOM ACTIONS (shrink-0) ─── */} {/* Primary Action Button: Save & Proceed immediately to Step 4 */} {/* Back Button */}
) }