import {notFound} from 'next/navigation';
import {MarketAssetPage} from '@/components/market-asset-page';
import {getCatalog} from '@/lib/server';
import {isWallexSymbol, wallexAssets} from '@/lib/wallex';

export const dynamic = 'force-dynamic';
type PageProps = {params: Promise<{symbol: string}>; searchParams: Promise<Record<string, string | string[] | undefined>>};

export async function generateMetadata({params}: PageProps) {
  const {symbol} = await params;
  const asset = wallexAssets.find(item => item.symbol === symbol);
  return {title: asset ? `${asset.title} | بازار پلانک` : 'دارایی یافت نشد | پلانک', description: asset?.description};
}

export default async function Page({params, searchParams}: PageProps) {
  const {symbol} = await params;
  if (!isWallexSymbol(symbol)) notFound();
  const query = await searchParams;
  const catalog = await getCatalog({designPreview: query.preview === 'design'});
  return <MarketAssetPage symbol={symbol} catalog={catalog}/>;
}
