'use client' import React from 'react' import { Card, CardHeader, CardTitle, CardContent, CardFooter } from '@/components/ui/card' import { Separator } from '@/components/ui/separator' import { Label } from '@/components/ui/label' import { Input } from '@/components/ui/input' import { Button } from '@/components/ui/button' import { Pencil, Trash2, UserPlus, ChevronRight, AlertCircle, Check } 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[] basketItems: any[] editingIdx: number | null editBasketItem: (idx: number) => void deleteBasketItem: (idx: number) => void deviceName: string setDeviceName: (name: string) => void addToBasket: () => void isNextStepDisabled: boolean hasActiveSelection: boolean nextStep: () => void prevStep: () => void } export function SummarySidebar({ visibleCategories, selections, products, moduleQuantities, billingLabel, oneTimeTotal, monthlyTotal, oneTimeNet, oneTimeTax, oneTimeGross, monthlyNet, monthlyTax, monthlyGross, updatePriceModifier, allCategoriesFilled, productValidationErrors, basketItems, editingIdx, editBasketItem, deleteBasketItem, deviceName, setDeviceName, addToBasket, isNextStepDisabled, hasActiveSelection, nextStep, prevStep, }: SummarySidebarProps) { return ( Zusammenfassung {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' : '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 && (Frei)} {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(actualPrice)} {' '}{billingLabel(prod.billing_interval)}
{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})` : ''} {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(mod.price * qty)}
) : null })}
) })}
) })} {oneTimeTotal > 0 && monthlyTotal > 0 ? (

Einmalig:

Netto: {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(oneTimeNet)}
zzgl. 19% MwSt.: {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(oneTimeTax)}
Gesamt (brutto): {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(oneTimeGross)}

Monatlich:

Netto: {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyNet)} / mtl.
zzgl. 19% MwSt.: {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyTax)} / mtl.
Gesamt (brutto): {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyGross)} / mtl.
) : oneTimeTotal > 0 ? (
Netto-Gesamtbetrag: {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(oneTimeNet)}
zzgl. 19% MwSt.: {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(oneTimeTax)}
Gesamtbetrag (brutto): {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(oneTimeGross)}
) : (
Netto-Gesamtbetrag: {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyNet)} / mtl.
zzgl. 19% MwSt.: {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyTax)} / mtl.
Gesamtbetrag (brutto): {new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(monthlyGross)} / mtl.
)} {updatePriceModifier.label && (

Update-Rabatt aktiv

{updatePriceModifier.label}

)} {!allCategoriesFilled && (

Bitte aus jeder Pflichtkategorie einen Artikel wählen.

)} {productValidationErrors.map((err, errIdx) => (

{err}

))} {basketItems.length > 0 && (

Warenkorb ({basketItems.length}):

{basketItems.map((item, idx) => (
{item.deviceName} {item.billingInterval === 'one_time' ? 'Kauf' : 'Abo'}
))}
)}
setDeviceName(e.target.value)} className="bg-white/5 border-white/10 text-white text-xs h-9 rounded-lg" />
) }