"use client"; import { Plus } from "lucide-react"; import { useState } from "react"; import { Button } from "@/components/ui/button"; import type { EditableTimeOff, TimeOffActionSet } from "./time-off-form-sheet"; import { TimeOffFormSheet } from "./time-off-form-sheet"; function formatRange(startDate: string, endDate: string): string { const start = new Date(`${startDate}T00:00:00`); const end = new Date(`${endDate}T00:00:00`); const startLabel = start.toLocaleDateString("en-GB", { weekday: "short", day: "numeric", month: "short" }); if (startDate === endDate) return startLabel; const endLabel = end.toLocaleDateString("en-GB", { weekday: "short", day: "numeric", month: "short" }); return `${startLabel} – ${endLabel}`; } export function TimeOffList({ upcoming, past, actions, appointmentHrefBase, }: { upcoming: EditableTimeOff[]; past: EditableTimeOff[]; actions?: TimeOffActionSet; appointmentHrefBase?: string; }) { const [sheetOpen, setSheetOpen] = useState(false); const [editing, setEditing] = useState(null); const openNew = () => { setEditing(null); setSheetOpen(true); }; const openEdit = (t: EditableTimeOff) => { setEditing(t); setSheetOpen(true); }; return (

Upcoming

{upcoming.length === 0 ? (

No upcoming time off.

) : (
    {upcoming.map((t) => (
  • ))}
)}
{past.length > 0 && (

Past

    {past.map((t) => (
  • {formatRange(t.startDate, t.endDate)}

    {t.reason &&

    {t.reason}

    }
  • ))}
)} setSheetOpen(false)} existing={editing} actions={actions} appointmentHrefBase={appointmentHrefBase} />
); }