"use client"; import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; import { createPortal } from "react-dom"; import { useAuth } from "@/hooks/useAuth"; import { useRouter } from "next/navigation"; import { apiFetch, API_BASE } from "@/lib/api"; import { ApiImage } from "@/components/shared/ApiImage"; import { useDismissingState } from "@/hooks/useDismissingState"; import { useSiteSettings } from "@/contexts/SiteSettingsContext"; import { useMyCampuses } from "@/hooks/useCampuses"; import { CampusBadge, CampusFilter, matchesCampus } from "@/components/shared/CampusFilter"; import { SavedFilters } from "@/components/shared/SavedFilters"; import { Calendar, Copy } from "lucide-react"; import { ChoicesEditor } from "@/components/shared/FormFieldExtras"; import { errorMessage } from "@/lib/utils"; import type { Event, EventAttachment, EventFormField, EventOption, EventSeries, Paginated, Section } from "@/types"; import { BackLink } from "@/components/shared/BackLink"; import { SessionsEditor, AttendanceSettings, keyed, sortSessions, sessionsProblem, defaultCertificate, type KeyedSession, type AttendanceDraft, } from "@/components/events/ScheduleEditor"; import { toSessionDraft, scheduleSummary } from "@/lib/sessions"; import { fetchApiFile, openBlob } from "@/lib/export"; // ─── helpers ──────────────────────────────────────────────────────────────── const cleanChoices = (opts: unknown): string[] => (Array.isArray(opts) ? opts.map(o => String(o).trim()).filter(Boolean) : []); function toLocalDT(input: string | Date | null | undefined): string { if (!input) return ""; const d = new Date(input); if (isNaN(d.getTime())) return ""; const y = d.getFullYear(); const m = String(d.getMonth() + 1).padStart(2, "0"); const day = String(d.getDate()).padStart(2, "0"); const hh = String(d.getHours()).padStart(2, "0"); const mm = String(d.getMinutes()).padStart(2, "0"); return `${y}-${m}-${day}T${hh}:${mm}`; } const DT_MIN = "2000-01-01T00:00"; const DT_MAX = "2099-12-31T23:59"; function DTInput({ label, value, onChange, hint, required }: { label: string; value: string; onChange: (v: string) => void; hint?: string; required?: boolean }) { return (
{hint}
}No fields yet.
: (Price is required — enter 0 for a free option.
}Add options first.
; return (No variants — uses base price (R{opt.price || "0"}).
: variants.map((v, vi) => (Add options first.
; return (No early-bird tiers.
} {opt.earlyBirdTiers.map((t, ti) => (No tiers for this variant.
} {v.earlyBirdTiers.map((t, ti) => (No sections yet.
} {sections.map((sec, i) => (No sections yet.
} {sections.map(sec => (No recipients selected — falling back to the event creator.
) : (Choose who receives new registration, payment, and daily summary emails for this event. Leave empty to send them to the event creator{creator ? <> ({creator.name}, {creator.email})> : null} instead.
{error &&Saved. You {[changedNotice.moved ? `moved ${changedNotice.moved} session${changedNotice.moved === 1 ? "" : "s"}` : "", changedNotice.cancelled ? `cancelled ${changedNotice.cancelled}` : ""].filter(Boolean).join(" and ")}. Tickets and calendar files show the new schedule, but people who registered aren't told automatically.
A copy of {source?.title} — check each step before saving. Registrations, coupons, attachments, kids check-in and volunteer roles aren't copied.
This copy still starts in the past.
}One registration and one ticket for every session, e.g. every Wednesday for 5 weeks. Check-in is per session.
}"All campuses" events show at every campus — for church-wide conferences and camps.
Groups separate events, like every year's camp, on one page with "Next in this series". Manage series
Defaults to your organisation's address — shown to attendees with a map link.
Auto-fills the first ticket option below — enter 0 for a free event.
}Define your ticket types or purchasable items. Variants and early-bird pricing are configured in the next two steps.
Add variants per option (e.g. Adult / Child, or t-shirt sizes). Leave blank if an option has only one price.
Set early-bird prices per variant (if variants exist) or per option. The cheapest applicable tier is used at registration time.
Group ticket options into named sections shown on the registration page (e.g. "Tickets", "Add-ons", "Accommodation").
{mode === "edit" && ev?.id ?Collect extra information from registrants (e.g. dietary requirements, t-shirt size, emergency contact).
Ask people what they thought, automatically after the event. Responses appear in Reports → Feedback summary.
{fbEnabled && ( <> {fbMeta?.sentAt && (Anyone who hasn't answered gets one reminder 3 days later.
Choose who receives new registration, payment, and daily summary emails for this event. Leave empty to send them to you (the event creator) instead.
Upload documents for attendees to download (e.g. waiver forms, info sheets, maps, schedules).
{mode === "edit" && ev?.id ?No files added. Files will be uploaded when the event is created.
: (Manage and create events
{events.length === 0 ? 'No events yet. Click "+ Add Event" to create one.' : "No events match the current filters."}
: