"use client";

import { usePathname, useSearchParams, useRouter } from "next/navigation";
import { useSimConfigure } from "@/features/services/hooks/useSimConfigure";
import { SimConfigureView as SimConfigureInnerView } from "@/features/services/components/sim/SimConfigureView";

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

  const vm = useSimConfigure(planId);

  const handleConfirm = () => {
    if (!vm.plan || !vm.validate()) return;
    const params = vm.buildCheckoutSearchParams();
    if (!params) return;
    const orderBasePath = pathname.startsWith("/account") ? "/account/order" : "/order";
    router.push(`${orderBasePath}?${params.toString()}`);
  };

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

export default SimConfigureContainer;
