import type { Metadata } from 'next'; import Link from 'next/link'; import { Suspense } from 'react'; import { FAMILIES } from '@rareindex/taxonomy'; import { PageHeader } from '@/components/ui/page-header'; import { Card, CardHeader, EmptyState, Table, th, td, tdNum, Badge, StatStrip } from '@/components/ui/primitives'; import { Tabs } from '@/components/ui/tabs'; import { FilterBar } from '@/components/ui/filter-bar'; import { Pagination } from '@/components/ui/pagination'; import { LotsIntelCards, LotsIntelTable } from '@/components/market/lots-table'; import { getLotOverview, listAuctionHouses, listAuctions, listLotsPaged, type LotSort } from '@/lib/queries/market-lists'; import { feeScheduleFor } from '@rareindex/valuation'; import { feeScheduleSummary, FeeConfidenceBadge } from '@/components/market/fee-schedule'; import { houseSlug, ENDING_WINDOWS, endingHours } from '@/lib/auction-house'; import { fmtDate, fmtNum, fmtRelative, cn } from '@/lib/format'; import { catName } from '@/lib/taxonomy'; import { sp1, spEnum, spInt, type SP } from '@/lib/search-params'; export const metadata: Metadata = { title: 'Auctions', description: 'Live and upcoming collectible auction lots with the buyer-pays all-in cost, the RareIndex Valuation and bid-vs-RIV, across auction houses worldwide.' }; const TABS = ['open', 'ending', 'below', 'results', 'houses'] as const; export default async function AuctionsPage({ searchParams }: { searchParams: Promise }) { const sp = await searchParams; const tab = spEnum(sp, 'tab', TABS, 'open'); const category = sp1(sp, 'category') ?? null; const house = sp1(sp, 'house') ?? null; const ending = sp1(sp, 'ending') ?? null; const below = sp1(sp, 'below') === '1' || tab === 'below'; const sort = spEnum(sp, 'sort', ['ending', 'value', 'discount', 'bids'] as const, tab === 'below' ? 'discount' : 'ending') as LotSort; const page = spInt(sp, 'page'); const hours = tab === 'ending' ? (endingHours(ending) ?? 72) : endingHours(ending); const [overview, houses, auctions, lots] = await Promise.all([ getLotOverview(), listAuctionHouses(), tab === 'houses' ? Promise.resolve([]) : listAuctions({ limit: 40, house }), tab === 'houses' ? Promise.resolve({ items: [], total: 0, page: 1, pageSize: 50 }) : listLotsPaged({ open: tab !== 'results', status: tab === 'results' ? 'ended' : null, endingWithinHours: hours, category, house, maxVsRiv: below ? -0.1 : null, sort: tab === 'results' ? (sort === 'ending' ? 'value' : sort) : sort, page, pageSize: 50, }), ]); const params = { tab, category: category ?? undefined, house: house ?? undefined, ending: ending ?? undefined, below: below && tab !== 'below' ? '1' : undefined, sort: sort !== 'ending' ? sort : undefined }; const q = (extra: Record) => { const u = new URLSearchParams(); for (const [k, v] of Object.entries({ ...params, ...extra })) if (v) u.set(k, v); const s = u.toString(); return `/auctions${s ? `?${s}` : ''}`; }; return (
Auction calendar → } /> {tab === 'houses' ? ( {houses.length ? ( {houses.map((h) => { const s = feeScheduleFor(h.house); return ( ); })}
House Buyer's premium Auctions Lots tracked Open
{h.house} {s ? ( {feeScheduleSummary(s)} ) : ( )} {fmtNum(h.auctions)} {fmtNum(h.lots)} {fmtNum(h.upcoming)}
) : ( )}
) : ( <>
({ 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' }, ...(tab === 'results' ? [] : [{ name: 'ending', label: 'Ending within', type: 'select' as const, options: ENDING_WINDOWS.map((w) => ({ value: w.id, label: w.label })), placeholder: tab === 'ending' ? '72 h' : 'Any', width: 'w-32' }]), { name: 'sort', label: 'Sort', type: 'select', options: [{ value: 'ending', label: 'Ending soonest' }, { value: 'discount', label: 'Most below RIV' }, { value: 'bids', label: 'Most bids' }, { value: 'value', label: 'Highest value' }], placeholder: tab === 'below' ? 'Most below RIV' : 'Ending soonest', width: 'w-40' }, ...(tab === 'below' || tab === 'results' ? [] : [{ name: 'below', label: 'Below RIV only', type: 'select' as const, options: [{ value: '1', label: 'Yes' }], placeholder: 'No', width: 'w-32' }]), ]} />

{fmtNum(lots.total)} lot{lots.total === 1 ? '' : 's'} {tab === 'ending' ? ` · ending within ${hours} h` : ''} {below ? ' · assessed all-in bid or estimate ≥ 10 % below the RIV of the same variant' : ''}

{!lots.items.length ? : null}
{auctions.length ? (
    {auctions.map((a) => (
  • {a.name}
    {a.status} {a.auctionHouse} · {a.endsAt ? `ends ${fmtDate(a.endsAt)} (${fmtRelative(a.endsAt)})` : a.startsAt ? `starts ${fmtDate(a.startsAt)}` : 'dates n/a'} · {a.lotsTracked} lots{a.lotCount ? ` / ${a.lotCount}` : ''} {a.categorySlugs.slice(0, 2).map((c) => ( · {catName(c)} ))}
  • ))}
) : ( )}
)}
); }