"use client"; import React from "react"; import type { Event } from "@/types"; import { bookableSessions, formatSessionWhen, sessionLabel } from "@/lib/sessions"; import { JoinWaitlistButton } from "@/components/events/JoinWaitlistButton"; // Tick boxes for the sessions of a "pick sessions" ticket. Full sessions (or ones with // fewer places than `quantity`) can't be ticked; with `waitlist`, they get a "Join // waitlist" button for that session instead. export function SessionPicker({ event, option, selected, onChange, quantity = 1, staff = false, unitPrice, waitlist }: { event: Pick; option: { id: string; sessionAvailability?: Record }; selected: string[]; onChange: (ids: string[]) => void; quantity?: number; staff?: boolean; unitPrice?: number; waitlist?: { eventId: string; guestsAllowed: boolean; variantId?: string | null; label: string } | null; }) { const sessions = bookableSessions(event, option, staff); if (sessions.length === 0) return

No sessions left to book.

; const toggle = (id: string) => onChange(selected.includes(id) ? selected.filter(x => x !== id) : [...selected, id]); const allOpen = sessions.filter(s => s.left === null || s.left >= Math.max(1, quantity)).map(s => s.id); return (
Choose your sessions{unitPrice !== undefined ? ` — R${unitPrice.toFixed(2)} each` : ""}
{sessions.map(s => { const full = s.left !== null && s.left < Math.max(1, quantity); const name = sessionLabel(s, event.sessions); return (
{full && waitlist && !selected.includes(s.id) && ( )}
); })}
); }