"use client";

import { useSearchParams, useRouter } from "next/navigation";
import { useSimConfigure } from "@/features/catalog/hooks/useSimConfigure";
import { SimConfigureView } from "@/features/catalog/components/sim/SimConfigureView";

export function SimConfigureContainer() {
  const searchParams = useSearchParams();
  const router = useRouter();
  const planId = searchParams.get("plan") || undefined;

  const vm = useSimConfigure(planId);

  const handleConfirm = () => {
    if (!vm.plan || !vm.validate()) return;
    const params = vm.buildCheckoutSearchParams();
    if (!params) return;
    router.push(`/checkout?${params.toString()}`);
  };

  return <SimConfigureView {...vm} onConfirm={handleConfirm} />;
}
