import { BackToCalendarLink } from "@/components/BackToCalendarLink";
import { notFound } from "next/navigation";
import { PARK_MAP } from "@/lib/parks";
import { ParkMonthCalendar } from "@/components/ParkMonthCalendar";
import { LiveRidePanel } from "@/components/LiveRidePanel";
import type { RideStatus, RidesFetchResult } from "@/lib/scrapers/sixflags";
import type { LiveRidesResult } from "@/lib/scrapers/queuetimes";
import { getTodayLocal } from "@/lib/env";
const BACKEND_URL = process.env.BACKEND_URL ?? "http://localhost:3001";
interface PageProps {
params: Promise<{ id: string }>;
searchParams: Promise<{ month?: string }>;
}
function parseMonthParam(param: string | undefined): string {
if (param && /^\d{4}-\d{2}$/.test(param)) {
const [y, m] = param.split("-").map(Number);
if (y >= 2020 && y <= 2030 && m >= 1 && m <= 12) {
return param;
}
}
return getTodayLocal().slice(0, 7);
}
export default async function ParkPage({ params, searchParams }: PageProps) {
const { id } = await params;
const { month: monthParam } = await searchParams;
const park = PARK_MAP.get(id);
if (!park) notFound();
const monthStr = parseMonthParam(monthParam);
const [year, month] = monthStr.split("-").map(Number);
const [calendarData, ridesData] = await Promise.all([
fetch(`${BACKEND_URL}/api/calendar/${id}/month?month=${monthStr}`, {
next: { revalidate: 300 },
}).then((r) => r.json()),
fetch(`${BACKEND_URL}/api/parks/${id}/rides`, {
next: { revalidate: 60 },
}).then((r) => r.json()),
]);
const { monthData, today } = calendarData;
const {
parkOpenToday,
isWeatherDelay,
liveRides,
scheduleFallback: ridesResult,
}: {
parkOpenToday: boolean;
isWeatherDelay: boolean;
liveRides: LiveRidesResult | null;
scheduleFallback: RidesFetchResult | null;
} = ridesData;
return (
{/* ── Header ─────────────────────────────────────────────────────────── */}
{park.name}
{park.location.city}, {park.location.state}
{/* ── Month Calendar ───────────────────────────────────────────────── */}
{/* ── Ride Status ─────────────────────────────────────────────────── */}
via queue-times.com
{liveRides.rides.some((r) => r.hasFastLane) && (
· Fast Lane via sixflags.com
)}
) : undefined}>
Rides
{liveRides ? (
) : ridesResult && !ridesResult.isExact ? (
{formatShortDate(ridesResult.dataDate)}
) : (
Today
)}
{liveRides ? (
) : (
)}
);
}
// ── Helpers ────────────────────────────────────────────────────────────────
function formatShortDate(iso: string): string {
return new Date(iso + "T00:00:00").toLocaleDateString("en-US", {
weekday: "short", month: "short", day: "numeric",
});
}
// ── Sub-components ─────────────────────────────────────────────────────────
function SectionHeading({ children, aside }: { children: React.ReactNode; aside?: React.ReactNode }) {
return (
{children}
{aside}
);
}
function LiveBadge() {
return (
Live
);
}
// ── Schedule ride list (Six Flags operating-hours API fallback) ────────────
function RideList({
ridesResult,
parkOpenToday,
}: {
ridesResult: RidesFetchResult | null;
parkOpenToday: boolean;
}) {
if (!parkOpenToday) {
return Park is closed today — no ride schedule available.;
}
if (!ridesResult || ridesResult.rides.length === 0) {
return Ride schedule is not yet available from the API.;
}
const { rides, isExact, dataDate, parkHoursLabel } = ridesResult;
const openRides = rides.filter((r) => r.isOpen);
const closedRides = rides.filter((r) => !r.isOpen);
return (
{/* Summary badge row */}
{openRides.length} open
{closedRides.length > 0 && (
{closedRides.length} closed / unscheduled
)}
{!isExact && (
Showing {formatShortDate(dataDate)} — live schedule updates daily
)}
{/* Two-column grid */}
{openRides.map((ride) => )}
{closedRides.map((ride) => )}
);
}
function RideRow({ ride, parkHoursLabel }: { ride: RideStatus; parkHoursLabel?: string }) {
const showHours = ride.isOpen && ride.hoursLabel && ride.hoursLabel !== parkHoursLabel;
return (
{ride.name}
{showHours && (
{ride.hoursLabel}
)}
);
}
function Callout({ children }: { children: React.ReactNode }) {
return (
{children}
);
}