"use client"; import React, { useEffect, useState } from "react"; import { apiFetch } from "@/lib/api"; import { formatDate } from "@/lib/date"; import type { KidsEvent } from "@/lib/kids"; type Props = { token: string | null; eventId: string; sessionId: string; onChange: (eventId: string, sessionId: string) => void; }; const STORAGE = "hope_events_kids_event"; /** Picks the kids event (and session) the desk or room screen works on; remembers the choice. */ export function KidsEventPicker({ token, eventId, sessionId, onChange }: Props) { const [events, setEvents] = useState(null); const [error, setError] = useState(null); useEffect(() => { if (!token) return; apiFetch("/api/kids/events", { authToken: token }) .then(list => { setEvents(list); if (eventId || !list.length) return; let remembered = ""; try { remembered = localStorage.getItem(STORAGE) || ""; } catch { /* ignore */ } const now = Date.now(); const current = list.find(e => e.id === remembered) || list.find(e => new Date(e.endDate).getTime() >= now) || list[0]; onChange(current.id, ""); }) .catch(e => setError(e?.message || "Could not load events")); }, [token]); // eslint-disable-line react-hooks/exhaustive-deps const event = events?.find(e => e.id === eventId); const pick = (id: string, sid = "") => { try { localStorage.setItem(STORAGE, id); } catch { /* ignore */ } onChange(id, sid); }; if (error) return
{error}
; if (events && !events.length) { return
No events have kids check-in switched on. A supervisor sets it up under Supervisor → Kids check-in setup.
; } return (
{event?.scheduleType === "sessions" && ( )}
); }