import {
  RiskPoolsConsole,
  type RiskPoolListFilter,
} from "@/modules/risk/risk-pools-console";

function parsePoolFilter(raw: string | undefined): RiskPoolListFilter {
  if (raw === "sold_out" || raw === "high_risk") {
    return raw;
  }
  return "all";
}

export default async function AdminDrawRiskPoolsPage(props: {
  params: Promise<{ drawId: string }>;
  searchParams: Promise<{ filter?: string }>;
}) {
  const { drawId } = await props.params;
  const { filter: filterRaw } = await props.searchParams;
  const id = Number(drawId);
  const filter = parsePoolFilter(filterRaw);

  return (
    <RiskPoolsConsole
      drawId={id}
      titleKey="allPoolsPageTitle"
      initialFilter={filter}
      defaultSort={filter === "high_risk" ? "usage_desc" : "number_asc"}
      allowSortChange
    />
  );
}
