import type { Metadata } from 'next';
import Link from 'next/link';
import { requireUser } from '@/lib/auth/session';
import { activeListingsForAssets, loadWatchlist } from '@/lib/account/queries';
import { getDisplay } from '@/lib/account/display';
import { toggleWatchAction } from '@/lib/account/actions';
import { PageHeader, btnDanger } from '@/components/account/page-header';
import { Card, CardHeader, Delta, EmptyState, Table, th, td, tdNum, Badge } from '@/components/ui/primitives';
import { fmtRelative, fmtPct, confidenceLabel } from '@/lib/format';
import { WatchAddForm, WatchNoteForm } from './forms';
export const metadata: Metadata = { title: 'Watchlist', robots: { index: false } };
export default async function WatchlistPage() {
const u = await requireUser('/watchlist');
const d = await getDisplay();
const rows = await loadWatchlist(u.id);
const assetRows = rows.filter((r) => r.item.targetType === 'asset');
const otherRows = rows.filter((r) => r.item.targetType !== 'asset');
const listingAgg = await activeListingsForAssets(assetRows.map((r) => r.item.targetId));
const lMap = new Map(listingAgg.map((l) => [l.assetId, l]));
return (
<>
{asset.categorySlug.replace(/_/g, ' ')} · added {fmtRelative(item.createdAt)}
)}
{assetRows.map(({ item, asset, stats }) => {
const l = lMap.get(item.targetId);
const since = item.baselineUsd && stats?.rivUsd ? (stats.rivUsd - item.baselineUsd) / item.baselineUsd : null;
const targetHit = item.targetPriceUsd && stats?.rivUsd ? stats.rivUsd <= item.targetPriceUsd : false;
return (
Asset
RIV
1d
30d
Since watch
Listings
Min ask
Target
Note
);
})}
{asset ? (
{stats?.rivUsd ? {d.money(stats.rivUsd)} : —}
{l ? Number(l.n) : 0}
{l?.minAsk ? d.money(Number(l.minAsk)) : —}
{item.targetPriceUsd ? (
{d.money(item.targetPriceUsd)}
{targetHit ?
Nothing here yet. Watch a category from its market page, or add one below.
) : (