import { useLocal } from "@/utils/use-local"; import { FC, ReactNode, useEffect } from "react"; import { Skeleton } from "../ui/skeleton"; export type BreadItem = { label: React.ReactNode; url?: string; onClick?: (ev: any) => void; }; type BreadcrumbProps = { on_load?: () => Promise; className?: string; value?: BreadItem[]; item?: PrasiItem; }; export const Breadcrumb: FC = ({ value, className, on_load, item, }) => { const local = useLocal({ list: [] as BreadItem[], status: "init" as "init" | "loading" | "ready", params: {}, }); useEffect(() => { if (value) { local.list = value; local.status = "ready"; } if (typeof on_load === "function") { local.status = "loading"; on_load().then((list) => { local.list = list; local.status = "ready"; local.render(); }); } local.render(); }, []); return (
{local.status !== "ready" ? ( ) : ( <> {local.list && (local.list || []).map((item, index): ReactNode => { const lastIndex = local.list.length - 1; return ( <> {index === lastIndex ? (

{item?.label}

) : (

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

)} {index !== lastIndex && (
)} ); })} )}
); };