// apps/dm/app/(landing)/reuse/_components/Lnb.tsx "use client"; import Image from "next/image"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useMemo, useState } from "react"; export type LnbItem = { label: string; href?: string; // href 없는 부모(2뎁스 컨테이너)도 허용 children?: LnbItem[]; }; function isExactActive(pathname: string, href?: string) { if (!href) return false; return pathname === href; } export default function Lnb({ title, items }: { title: string; items: LnbItem[] }) { const pathname = usePathname(); // ✅ 현재 경로가 속한 2depth 그룹을 기본 open const defaultOpenLabel = useMemo(() => { const found = items.find((it) => it.children?.some((c) => isExactActive(pathname, c.href))); return found?.label ?? null; }, [items, pathname]); // ✅ 아코디언: 한 번에 하나만 열리도록 openLabel 1개만 관리 const [openLabel, setOpenLabel] = useState(defaultOpenLabel); return ( ); }