import { useLocal } from "@/utils/use-local"; import { FC, ReactNode, useEffect } from "react"; import { FieldLoading } from "../ui/field-loading"; 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; } return (
{local.loading ? ( ) : ( <> {(Array.isArray(local.value) ? local.value : []).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 && (
)} ); } )} )}
); };