'use client'; import { Appointment } from '@/types/appointment'; interface AppointmentListProps { appointments: Appointment[]; onToggleDone?: (id: string) => void; onEdit?: (appointment: Appointment) => void; onDelete?: (id: string) => void; } const weekdays = ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa']; const formatDate = (iso: string) => { const d = new Date(iso); const day = String(d.getDate()).padStart(2, '0'); const m = String(d.getMonth() + 1).padStart(2, '0'); return `${day}.${m}.${d.getFullYear()}`; }; const formatTime = (iso: string) => { const d = new Date(iso); const h = String(d.getHours()).padStart(2, '0'); const min = String(d.getMinutes()).padStart(2, '0'); return `${h}:${min}`; }; const getWeekday = (iso: string) => weekdays[new Date(iso).getDay()]; export default function AppointmentList({ appointments, onToggleDone, onEdit, onDelete, }: AppointmentListProps) { const hasActions = Boolean(onEdit || onDelete); if (appointments.length === 0) { return (
Keine Termine vorhanden.
); } // Erledigte Einträge hinter die offenen schieben; innerhalb der Gruppen // aufsteigend nach Termin sortieren. const sorted = [...appointments].sort((a, b) => { if (a.erledigt !== b.erledigt) return a.erledigt ? 1 : -1; return new Date(a.termin).getTime() - new Date(b.termin).getTime(); }); return (
{hasActions && } {sorted.map((app, index) => ( onEdit(app) : undefined} className={`border-b border-gray-300 hover:bg-gray-100 ${ onEdit ? 'cursor-pointer' : '' } ${ app.erledigt ? 'bg-green-50 text-gray-400' : index % 2 === 0 ? 'bg-white' : 'bg-gray-50' }`} > {hasActions && ( )} ))}
Erledigt Arzt Fachrichtung Datum Tag Zeit BemerkungenAktion
e.stopPropagation()} > onToggleDone(app.id) : undefined } /> {app.arztName} {app.arztArt || '-'} {formatDate(app.termin)} {getWeekday(app.termin)} {formatTime(app.termin)} {app.bemerkungen || '-'} e.stopPropagation()} >
{onEdit && ( )} {onDelete && ( )}
); }