import type { Metadata } from 'next'; import { Suspense } from 'react'; import { PageHeader } from '@/components/ui/page-header'; import { Segmented } from '@/components/ui/tabs'; import { FilterBar } from '@/components/ui/filter-bar'; import { Card, EmptyState, Badge } from '@/components/ui/primitives'; import { listAuctionHouses, listAuctions } from '@/lib/queries/market-lists'; import { fmtDate, fmtRelative } from '@/lib/format'; import { catName } from '@/lib/taxonomy'; import { FAMILIES } from '@rareindex/taxonomy'; import { sp1, spEnum, withParams, type SP } from '@/lib/search-params'; export const metadata: Metadata = { title: 'Auction calendar', description: 'Upcoming collectible auctions today, this week and this month, filterable by category, house and region.' }; export default async function CalendarPage({ searchParams }: { searchParams: Promise }) { const sp = await searchParams; const range = spEnum(sp, 'range', ['today', 'week', 'month'] as const, 'week'); const category = sp1(sp, 'category') ?? null; const house = sp1(sp, 'house') ?? null; const now = new Date(); const to = new Date(now.getTime() + (range === 'today' ? 1 : range === 'week' ? 7 : 31) * 86_400_000); const [auctions, houses] = await Promise.all([listAuctions({ from: now, to, category, house, limit: 200 }), listAuctionHouses()]); const byDay = new Map(); for (const a of auctions) { const d = (a.endsAt ?? a.startsAt ?? now).toISOString().slice(0, 10); (byDay.get(d) ?? byDay.set(d, []).get(d)!).push(a); } const params = { category: category ?? undefined, house: house ?? undefined }; return (
({ value: f.slug, label: f.name })), width: 'w-44' }, { name: 'house', label: 'House', type: 'select', options: houses.map((h) => ({ value: h.house, label: h.house })), width: 'w-44' }]} />
{byDay.size ? (
{[...byDay.entries()].sort(([a], [b]) => (a < b ? -1 : 1)).map(([day, items]) => (
{fmtDate(day, { month: 'long' })}
    {items.map((a) => (
  • {a.name}
    {a.auctionHouse} {a.location ? ` · ${a.location}` : ''} {a.categorySlugs.length ? ` · ${a.categorySlugs.slice(0, 3).map(catName).join(', ')}` : ''}
    {a.status} {a.endsAt ? `closes ${fmtDate(a.endsAt, { time: true })} (${fmtRelative(a.endsAt)})` : a.startsAt ? `starts ${fmtDate(a.startsAt, { time: true })}` : ''} · {a.lotsTracked} lots
  • ))}
))}
) : ( )}
); }