import type { Metadata } from 'next'; import Link from 'next/link'; import { requireUser } from '@/lib/auth/session'; import { listCollections, portfolioHistory, indexSeries } from '@/lib/account/queries'; import { summarizePortfolio, rebase } from '@/lib/account/portfolio'; import { loadItems } from '@/lib/account/queries'; import { getDisplay } from '@/lib/account/display'; import { PageHeader, btnPrimary, btnSecondary } from '@/components/account/page-header'; import { SummaryStats, AllocationCards } from '@/components/account/portfolio-widgets'; import { LineChart } from '@/components/account/charts'; import { Card, CardHeader, Delta, EmptyState, Badge } from '@/components/ui/primitives'; import { fmtRelative } from '@/lib/format'; import { CreateCollectionForm } from './create-form'; export const metadata: Metadata = { title: 'Collections', robots: { index: false } }; export default async function CollectionsPage({ searchParams }: { searchParams: Promise> }) { const sp = await searchParams; const u = await requireUser('/collections'); const d = await getDisplay(); const cols = await listCollections(u.id); const allItems = await loadItems(cols.map((c) => c.collection.id)); const total = summarizePortfolio(allItems); const history = await portfolioHistory(u.id); const rare = history.length ? await indexSeries('RARE', history[0]!.date) : []; const mine = rebase(history.map((h) => ({ date: h.date, value: h.valueUsd }))); const bench = rebase(rare); return ( <> {sp.welcome ? (

Welcome to RareIndex{u.name ? `, ${u.name}` : ''}.

Start by creating a collection and adding what you own. Every item is valued with the RareIndex Valuation (RIV) when enough market evidence exists — and marked honestly when it does not.

) : null} Deal Radar New collection } /> {d.fallback ?

No exchange rate loaded for your display currency yet — values are shown in USD.

: null}
My Index →} />
1 ? [{ name: 'RARE', points: bench, color: 'var(--ri-fg-subtle)', dashed: true }] : [])]} height={200} /> {history.length ? (
My portfolio {bench.length > 1 ? ( RARE Global Collectibles Index ) : ( RARE index history is not available yet for this period. )}
) : null}
Collections
{cols.length}
Items · units
{total.itemCount} · {total.unitCount}
Categories
{total.allocationByCategory.length}
Awaiting valuation
{total.unvaluedCount}
Display currency
{d.currency}
RIV = RareIndex Valuation. Each item shows whether its value comes from a graded-variant RIV, the asset-level RIV, or a manual value you entered. Nothing is invented: items without market evidence stay unvalued.
{total.valuedCount > 0 ?
: null}

Your collections

{cols.length === 0 ? ( ) : (
{cols.map(({ collection: c, summary: s }) => (

{c.color ? : null} {c.name}

{s.itemCount} item{s.itemCount === 1 ? '' : 's'} · updated {fmtRelative(c.updatedAt)}

{c.kind !== 'collection' ? {c.kind} : null} {c.isPublic ? public : null}

{s.valuedCount ? d.money(s.valueUsd) : '—'}

{s.valuedCount ? `${s.valuedCount}/${s.itemCount} valued` : 'no valuation yet'}

{c.kind === 'wishlist' && c.budgetUsd ? (

Budget {d.money(c.budgetUsd)} · wishlist value {d.money(s.valueUsd)}

) : null} ))}
)}
); }