"use client"; import { useState } from "react"; import { AbsenceReason } from "@prisma/client"; import { CalendarDays, Circle, MessageSquareText, UserRound } from "lucide-react"; import { reasonColor, reasonLabel } from "@/lib/absence-utils"; import { Badge } from "@/components/ui/badge"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; export type AbsenceTableItem = { id: string; childName: string; familyName: string; reason: AbsenceReason; note: string | null; startDate: string; endDate: string; }; export function AbsenceTable({ absences }: { absences: AbsenceTableItem[] }) { const [activeAbsence, setActiveAbsence] = useState( null, ); return ( <> Kind Zeitraum Grund Bemerkung Status {absences.map((absence) => ( setActiveAbsence(absence)} >
{getInitials(absence.childName)}

{absence.childName}

{absence.familyName}

{formatDateRange(absence.startDate, absence.endDate)} {reasonLabel(absence.reason)} {absence.note || "Keine Bemerkung hinterlegt."} Bestätigt
))}
!open && setActiveAbsence(null)} > {activeAbsence ? ( <> {activeAbsence.childName} {activeAbsence.familyName}
) : null}
); } function DetailLine({ icon: Icon, label, value, dotColor, }: { icon: typeof CalendarDays; label: string; value: string; dotColor?: string; }) { return (

{dotColor ? ( ) : ( )} {label}

{value}

); } function getInitials(name: string) { return name .split(" ") .filter(Boolean) .slice(0, 2) .map((part) => part[0]) .join("") .toUpperCase(); } export function formatDateRange(startDate: string, endDate: string) { const start = new Date(`${startDate}T00:00:00`); const end = new Date(`${endDate}T00:00:00`); const startLabel = start.toLocaleDateString("de-DE", { day: "2-digit", month: "2-digit", }); const endLabel = end.toLocaleDateString("de-DE", { day: "2-digit", month: "2-digit", year: "numeric", }); return startDate === endDate ? endLabel : `${startLabel} - ${endLabel}`; }