import NumberPlayClient from "./NumberPlayClient";
import type { MaxTermCount, ProblemCount } from "@/store/gameStore";

interface NumberPlayPageProps {
  searchParams?: {
    count?: string | string[];
    terms?: string | string[];
  };
}

function parseProblemCount(count?: string | string[]): ProblemCount {
  if (Array.isArray(count)) {
    return parseProblemCount(count[0]);
  }

  return count === "5" ? 5 : 10;
}

function parseMaxTermCount(terms?: string | string[]): MaxTermCount {
  if (Array.isArray(terms)) {
    return parseMaxTermCount(terms[0]);
  }

  if (terms === "3") return 3;
  if (terms === "4") return 4;

  return 2;
}

export default function NumberPlayPage({ searchParams }: NumberPlayPageProps) {
  return (
    <NumberPlayClient
      problemCount={parseProblemCount(searchParams?.count)}
      maxTermCount={parseMaxTermCount(searchParams?.terms)}
    />
  );
}
