'use client' import { useFetch } from '@/hooks/use-fetch' import { Sheet, SheetContent, SheetHeader, SheetTitle, } from '@/components/ui/sheet' import { Badge } from '@/components/ui/badge' import { Skeleton } from '@/components/ui/skeleton' import { ScrollArea } from '@/components/ui/scroll-area' import { formatEuro, formatDate } from '@/lib/format' import { useAos } from '@/store/aos' import { Building2, Globe, Mail, Phone, MapPin, FileText, Receipt, FolderKanban, KeyRound, ShieldCheck, Clock, } from 'lucide-react' interface CompanyDetail { company: { id: string name: string legalForm: string | null vatId: string | null registerCourt: string | null registerNumber: string | null website: string | null email: string | null phone: string | null city: string | null zip: string | null street: string | null source: string | null tags: string | null createdAt: string } persons: { id: string; firstName: string; lastName: string; email: string | null; role: string | null; phone: string | null }[] deals: { id: string; title: string; stage: string; valueCents: number; probability: number }[] projects: { id: string; name: string; status: string; type: string }[] invoices: { id: string; number: string; status: string; grossCents: number; issueDate: string }[] licenses: { id: string; key: string; product: string; status: string; activations: { id: string }[] }[] leads: { id: string; companyName: string; score: number; status: string }[] timeline: { kind: string; date: string; title: string; meta: string; valueCents: number | null }[] consent: { legalBasis: string purpose: string source: string recordedAt: string evidence: string } } export function CompanyDrawer() { const { selectedCompanyId, setSelectedCompany } = useAos() const { data, loading } = useFetch( selectedCompanyId ? `/api/aos/crm/companies/${selectedCompanyId}` : null ) return ( !o && setSelectedCompany(null)}> Firmendetails {loading || !data ? (
) : ( <> {data.company.name} {data.company.legalForm && ( {data.company.legalForm} )}
{data.company.website && ( {data.company.website} )} {data.company.email && {data.company.email}} {data.company.phone && {data.company.phone}} {data.company.city && {data.company.zip} {data.company.city}}
{/* Legal */}

Stammdaten

{data.company.tags && (
{data.company.tags.split(',').map((t) => ( {t.trim()} ))}
)}
{/* DSGVO consent */}

DSGVO-Konsens

{/* Persons */}

Ansprechpartner ({data.persons.length})

{data.persons.map((p) => (

{p.firstName} {p.lastName}

{p.role ?? '—'}

{p.email &&

{p.email}

}
))} {data.persons.length === 0 && No persons.}
{/* Timeline */}

Timeline

{data.timeline.map((t, i) => { const Icon = t.kind === 'deal' ? FileText : t.kind === 'invoice' ? Receipt : t.kind === 'project' ? FolderKanban : KeyRound return (

{t.title}

{t.valueCents ? {formatEuro(t.valueCents)} : null}

{formatDate(t.date)} · {t.meta}

) })} {data.timeline.length === 0 && Noch keine Aktivität.}
{/* Licenses + Invoices quick links */}

Lizenzen

{data.licenses.map((l) => (

{l.product}

{l.key}
))} {data.licenses.length === 0 && Keine Lizenzen.}

Rechnungen

{data.invoices.slice(0, 5).map((i) => (
{i.number} {i.status}

{formatEuro(i.grossCents)}

))} {data.invoices.length === 0 && Keine Rechnungen.}
)}
) } function Field({ label, value, mono }: { label: string; value?: string | null; mono?: boolean }) { return (

{label}

{value ?? '—'}

) } function ConsentRow({ label, value }: { label: string; value: string }) { return (
{label}: {value}
) } function Empty({ children }: { children: React.ReactNode }) { return

{children}

}