'use client' import { useEffect, useState } from 'react' import { Language, FMComputeResponse } from '@/lib/types' import { t } from '@/lib/i18n' import GradientText from '../ui/GradientText' import FadeInView from '../ui/FadeInView' import FinancialChart from '../ui/FinancialChart' import KPICard from '../ui/KPICard' import WaterfallChart from '../ui/WaterfallChart' import AnnualCashflowChart from '../ui/AnnualCashflowChart' type FinTab = 'overview' | 'guv' | 'cashflow' interface FinancialsSlideProps { lang: Language } export default function FinancialsSlide({ lang }: FinancialsSlideProps) { const i = t(lang) const [activeTab, setActiveTab] = useState('overview') const [data, setData] = useState(null) const [loading, setLoading] = useState(true) const [guv, setGuv] = useState([]) const de = lang === 'de' // Auto-load Finanzplan data useEffect(() => { async function load() { try { // Compute Finanzplan and get FMResult format const res = await fetch('/api/financial-model/compute', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ source: 'finanzplan' }), }) if (res.ok) { const d = await res.json() setData(d) } // Load GuV separately const guvRes = await fetch('/api/finanzplan/guv') if (guvRes.ok) { const guvData = await guvRes.json() setGuv(guvData.rows || []) } } catch (e) { console.error('Failed to load Finanzplan:', e) } finally { setLoading(false) } } load() }, []) const summary = data?.summary const results = data?.results || [] const lastResult = results.length > 0 ? results[results.length - 1] : null // Find break-even month (first month where revenue > costs) const breakEvenMonth = results.findIndex(r => r.revenue_eur > r.total_costs_eur && r.revenue_eur > 0) const breakEvenYear = breakEvenMonth >= 0 ? results[breakEvenMonth]?.year : null const tabs: { id: FinTab; label: string }[] = [ { id: 'overview', label: de ? 'Übersicht' : 'Overview' }, { id: 'guv', label: de ? 'GuV (Jahres)' : 'P&L (Annual)' }, { id: 'cashflow', label: de ? 'Cashflow' : 'Cash Flow' }, ] if (loading) { return (
) } return (

{i.financials.title}

{i.financials.subtitle}

{/* Hero KPI Cards */}
= 0 ? 'up' : 'neutral'} color="#eab308" delay={0.2} subLabel={breakEvenMonth >= 0 ? `${de ? 'Monat' : 'Month'} ${breakEvenMonth + 1}` : ''} /> 0 ? 'up' : 'down'} color="#a855f7" delay={0.25} subLabel="EUR" />
{/* Tab Navigation */}
{tabs.map((tab) => ( ))}
{/* TAB: Overview — monatlicher Chart */} {activeTab === 'overview' && (

{de ? 'Umsatz vs. Kosten (60 Monate)' : 'Revenue vs. Costs (60 months)'}

{de ? 'Umsatz' : 'Revenue'} {de ? 'Kosten' : 'Costs'} Cash

{de ? 'Cash-Flow (Quartal)' : 'Cash Flow (Quarterly)'}

{data && }

{de ? 'Jährlicher Cashflow' : 'Annual Cash Flow'}

{data && ( )}
)} {/* TAB: GuV — aus Finanzplan DB */} {activeTab === 'guv' && (

{de ? 'Gewinn- und Verlustrechnung (5 Jahre)' : 'Profit & Loss Statement (5 Years)'}

{de ? 'Alle Werte in EUR' : 'All values in EUR'}

{[2026, 2027, 2028, 2029, 2030].map(y => ( ))} {guv.map((row: any) => { const label = row.row_label || '' const values = row.values || {} const isBold = row.is_sum_row || label.includes('EBIT') || label.includes('Summe') || label.includes('Rohergebnis') || label.includes('Gesamtleistung') || label.includes('Jahresueberschuss') || label.includes('Ergebnis') return ( {[2026, 2027, 2028, 2029, 2030].map(y => { const v = Math.round(values[`y${y}`] || 0) return ( ) })} ) })}
{de ? 'Position' : 'Item'}{y}
{label} 0 ? (isBold ? 'text-white/80' : 'text-white/50') : 'text-white/15'} ${isBold ? 'font-bold' : ''}`}> {v === 0 ? '—' : v.toLocaleString('de-DE')}
)} {/* TAB: Cashflow */} {activeTab === 'cashflow' && data && (

{de ? 'Jährlicher Cashflow & Liquiditätsentwicklung' : 'Annual Cash Flow & Liquidity Development'}

)}
) }