"use client"; import { ChevronRight, Home } from "lucide-react"; import { Fragment, useEffect } from "react"; import { useCatalogManager } from "./use-catalog-store"; export function BreadcrumbBar({ onSelectPage, }: { onSelectPage: (id: number) => void; }) { const { state, dispatch, catalogType } = useCatalogManager(); const { selectedPageId, ancestors } = state; const catQs = catalogType === "bc" ? "&catalog=bc" : ""; useEffect(() => { if (!selectedPageId || selectedPageId <= 0) { dispatch({ type: "SET_ANCESTORS", ancestors: [] }); return; } const ac = new AbortController(); fetch(`/api/admin/catalog/tree?ancestors=${selectedPageId}${catQs}`, { signal: ac.signal, }) .then((r) => r.json()) .then((d) => { if (!ac.signal.aborted) { dispatch({ type: "SET_ANCESTORS", ancestors: d.ancestors ?? [] }); } }) .catch((error) => console.error("[Breadcrumb] Failed to fetch ancestors:", error), ); return () => ac.abort(); }, [selectedPageId, dispatch, catQs]); if (!selectedPageId || ancestors.length === 0) return null; return (