import Link from 'next/link'; import { CalendarDays, ChevronLeft, ChevronRight, MapPin, Plus, Users, } from 'lucide-react'; import { getTranslations } from 'next-intl/server'; import { createEventManagementApi } from '@kit/event-management/api'; import { formatDate } from '@kit/shared/dates'; import { getSupabaseServerClient } from '@kit/supabase/server-client'; import { Badge } from '@kit/ui/badge'; import { Button } from '@kit/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@kit/ui/card'; import { AccountNotFound } from '~/components/account-not-found'; import { CmsPageShell } from '~/components/cms-page-shell'; import { EmptyState } from '~/components/empty-state'; import { StatsCard } from '~/components/stats-card'; import { EVENT_STATUS_VARIANT, EVENT_STATUS_LABEL_KEYS } from '~/lib/status-badges'; interface PageProps { params: Promise<{ account: string }>; searchParams: Promise>; } export default async function EventsPage({ params, searchParams }: PageProps) { const { account } = await params; const search = await searchParams; const client = getSupabaseServerClient(); const t = await getTranslations('cms.events'); const { data: acct } = await client .from('accounts') .select('id') .eq('slug', account) .single(); if (!acct) return ; const page = Number(search.page) || 1; const api = createEventManagementApi(client); const events = await api.listEvents(acct.id, { page }); // Fetch registration counts for all events on this page const eventIds = events.data.map((eventItem: Record) => String(eventItem.id), ); const registrationCounts = await api.getRegistrationCounts(eventIds); // Pre-compute stats before rendering const uniqueLocationCount = new Set( events.data .map((eventItem: Record) => eventItem.location) .filter(Boolean), ).size; const totalCapacity = events.data.reduce( (sum: number, eventItem: Record) => sum + (Number(eventItem.capacity) || 0), 0, ); return (
{/* Header */}

{t('description')}

{/* Stats */}
} /> } /> } />
{/* Table or Empty State */} {events.data.length === 0 ? ( } title={t('noEvents')} description={t('noEventsDescription')} actionLabel={t('newEvent')} actionHref={`/home/${account}/events/new`} /> ) : ( {t('allEvents')} ({events.total})
{events.data.map((event: Record) => { const eventId = String(event.id); const regCount = registrationCounts[eventId] ?? 0; return ( ); })}
{t('name')} {t('eventDate')} {t('eventLocation')} {t('capacity')} {t('status')} {t('registrations')}
{String(event.name)} {formatDate(event.event_date as string)} {String(event.location ?? '—')} {event.capacity != null ? String(event.capacity) : '—'} {t(EVENT_STATUS_LABEL_KEYS[String(event.status)] ?? String(event.status))} {regCount}
{/* Pagination */} {events.totalPages > 1 && (
{t('paginationPage', { page: events.page, totalPages: events.totalPages, })}
{events.page > 1 && ( )} {events.page < events.totalPages && ( )}
)}
)}
); }