// Auteur : Simon-Pierre Boucher — contact@spboucher.ai
import { notFound } from "next/navigation";
import { estimateManual } from "@/lib/estimator";
import ResultView from "@/components/ResultView";

export const dynamic = "force-dynamic";

export default async function ManualEstimationPage({
  searchParams,
}: {
  searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
  const sp = await searchParams;
  const one = (k: string) => {
    const v = sp[k];
    return Array.isArray(v) ? v[0] : v;
  };
  const municipality = one("municipality");
  const typeProp = one("typeProp");
  if (!municipality || !typeProp) notFound();
  const num = (k: string) => {
    const v = one(k);
    const n = v ? Number(v) : NaN;
    return Number.isFinite(n) ? n : undefined;
  };
  const data = estimateManual({
    municipality,
    typeProp,
    floorArea: num("floorArea"),
    yearBuilt: num("yearBuilt"),
    landArea: num("landArea"),
  });
  if (!data) notFound();
  return <ResultView data={data} />;
}
