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

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

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" || filter === "active" ? "usage_desc" : "number_asc"}
      allowSortChange
    />
  );
}
