"use client"; import { useMemo } from "react"; import { useSearchParams, useRouter } from "next/navigation"; import dynamic from "next/dynamic"; import { cn } from "@/lib/utils"; const BuyingGuideList = dynamic( () => import("@/components/buying-guide/BuyingGuideList"), { ssr: false } ); const LaserFinderPanel = dynamic( () => import("@/components/buying-guide/LaserFinderPanel"), { ssr: false } ); const BuyingGuideProductClient = dynamic( () => import("@/components/buying-guide/BuyingGuideProductClient"), { ssr: false } ); const TABS = [ { key: "list", label: "Buying Guide" }, { key: "finder", label: "Laser Finder" }, ]; export default function BuyingGuideSwitcher() { const searchParams = useSearchParams(); const router = useRouter(); const active = useMemo(() => searchParams.get("tab") || "list", [searchParams]); const productId = searchParams.get("product"); const setTab = (key: string) => { const sp = new URLSearchParams(Array.from(searchParams.entries())); sp.set("tab", key); // When changing tabs, ensure product detail (if open) is cleared sp.delete("product"); router.push(`?${sp.toString()}`, { scroll: false }); }; return (