import { useLocal } from "lib/utils/use-local"; import { FC, ReactNode, useEffect } from "react"; import { FieldLoading } from "../ui/field-loading"; import { ChevronLeft } from "lucide-react"; export type BreadItem = { label: React.ReactNode; url?: string; onClick?: (ev: any) => void; }; type BreadcrumbProps = { on_load?: (e?: any) => Promise; className?: string; value?: BreadItem[]; item?: PrasiItem; }; export const Breadcrumb: FC = ({ value, className }) => { const local = useLocal({ value: value, loading: false, loaded: false }); useEffect(() => { if (local.loaded) { local.loaded = false; local.render(); } }, [location.pathname, location.hash]); if (value instanceof Promise) { if (!local.loaded) { local.loading = true; value.then((v) => { local.value = v; local.loading = false; local.loaded = true; local.render(); }); } } else { local.value = value; } const list = Array.isArray(local.value) ? local.value : []; return (
{local.loading ? ( ) : ( <> {(!local.value || local.value.length === 0) && isEditor && ( <> {" "} {isDesktop ? ( "Breadcrumb" ) : (

Breadcrumb

)} )} {isDesktop && ( <> {list.map((cur, index): ReactNode => { const lastIndex = (local.value || []).length - 1; return ( <> {index === lastIndex ? (

{cur?.label}

) : (

{ if (isEditor) return; if (cur.url) navigate(cur.url || ""); if (cur.onClick) cur.onClick(ev); }} > {cur?.label}

)} {index !== lastIndex && (
)} ); })} )} {isMobile && ( <> {list.length > 1 && (
{ const cur = list[list.length - 2]; if (isEditor) return; if (cur.url) navigate(cur.url || ""); if (cur.onClick) cur.onClick(ev); }} >

{list[list.length - 1].label}

)} {list.length === 1 && (

{list[0].label}

)} )} )}
); };