"use client"; import { CalendarClock } from "lucide-react"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { Button } from "@/components/ui/Button"; import { FILTER_SELECT_CLASS, KalenderKnopf, useDatumEingabe } from "@/components/ui/Field"; import { fmtDate } from "@/lib/format"; type AsOfPickerProps = { asOf: string; today: string; /** Placements projected from effective-dated changes not yet applied. */ projectedCount: number; /** Earliest date the assignment history covers; before that it is today's placement. */ historyStartsAt: string | null; }; export function AsOfPicker({ asOf, today, projectedCount, historyStartsAt }: AsOfPickerProps) { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); function setAsOf(value: string | undefined) { const sp = new URLSearchParams(searchParams.toString()); if (value && value !== today) sp.set("asOf", value); else sp.delete("asOf"); router.push(sp.size > 0 ? `${pathname}?${sp}` : pathname, { scroll: false }); } // Dieselben Regeln wie in DateField: TT.MM.JJJJ, gemeldet wird nur ein // vollständiges Datum. Hier ist jede Meldung eine Navigation. const datum = useDatumEingabe({ value: asOf, onChange: (d) => setAsOf(d || undefined) }); const isToday = asOf === today; const isFuture = asOf > today; // The assignment history only reaches back to historyStartsAt; asking for a // date before that yields today's placement for everyone, which is worth // saying out loud rather than quietly implying. const beforeHistory = historyStartsAt !== null && asOf < historyStartsAt; return (
Vorschau: {projectedCount > 0 ? `${projectedCount} geplante Versetzung(en) oder Beförderung(en) sind eingerechnet.` : "Für diesen Zeitraum sind keine Versetzungen vorgemerkt."}{" "} Ein-/Austritte und Karenzen sind berücksichtigt.
)} {beforeHistory && (Vor dem {fmtDate(historyStartsAt)} wurde die Zuordnungshistorie noch nicht aufgezeichnet. Wer beschäftigt war, stimmt; Team und Vorgesetzte zeigen für diesen Stichtag die heutige Zuordnung.
)}