"use client"; import { CalendarX2Icon, SearchXIcon } from "lucide-react"; import { Fragment } from "react"; import { EventListItem } from "@/components/admin/EventListItem"; import { Button } from "@/components/ui/button"; import { Skeleton } from "@/components/ui/skeleton"; import { formatDay } from "@/lib/dates"; import { groupByMonth, type Range, type Sort } from "@/lib/filter"; import type { CalendarEvent } from "@/lib/types"; /** * The list itself: grouped by month when sorted by start (what people scan * for), flat when sorted by creation date (where month headings would repeat * and mislead). */ export function EventList({ events, now, sort, range, query, loading, noCalendars, publishingId, todayMarker, onOpen, onPublish, onClearQuery, }: { events: CalendarEvent[]; now: Date; sort: Sort; range: Range; query: string; loading: boolean; noCalendars: boolean; publishingId: number | null; /** Index into `events` to show the "Heute" marker in front of (`events.length` = after the last); null for none. */ todayMarker: number | null; onOpen?: (event: CalendarEvent) => void; onPublish: (event: CalendarEvent) => void; onClearQuery: () => void; }) { if (noCalendars) { return } title="Kein Kalender ausgewählt" text="Wähle oben mindestens einen Kalender." />; } if (events.length === 0 && loading) { return ; } if (events.length === 0) { if (query.trim() !== "") { return ( } title={`Keine Termine für „${query.trim()}“`} text="Die Suche berücksichtigt Titel und Ort." action={ } /> ); } const text = { future: "Keine kommenden Termine.", past: "Keine vergangenen Termine.", all: "Noch keine Termine." }[range]; return } title={text} text="In den ausgewählten Kalendern ist nichts eingetragen." />; } const markerBefore = todayMarker !== null && todayMarker < events.length ? events[todayMarker].eventId : null; const marker = ; const item = (event: CalendarEvent) => ( {event.eventId === markerBefore && marker} ); if (sort.startsWith("created")) { return
    {events.map(item)}
; } return (
{groupByMonth(events, now).map((group, i) => (

{group.label}

    {group.events.map(item)}
))} {todayMarker === events.length &&
    {marker}
}
); } /** Where today falls in the list. The page scrolls it into view in the "Alle" range. */ function TodayMarker({ now }: { now: Date }) { return (
  • Heute · {formatDay(now)}
  • ); } function Empty({ icon, title, text, action }: { icon: React.ReactNode; title: string; text: string; action?: React.ReactNode }) { return (
    {icon}

    {title}

    {text}

    {action &&
    {action}
    }
    ); } function ListSkeleton() { return (
    {Array.from({ length: 5 }, (_, i) => (
    ))}
    ); }