import { ucFirstAllSnakeToPascalWithSpaces } from "core/utils"; import { useMemo } from "react"; import { TbArrowLeft, TbDots } from "react-icons/tb"; import { Link, useLocation } from "wouter"; import { IconButton } from "../../components/buttons/IconButton"; import { Dropdown } from "../../components/overlay/Dropdown"; import { useEvent } from "../../hooks/use-event"; export type BreadcrumbsProps = { path: string | string[]; backTo?: string; onBack?: () => void; }; export const Breadcrumbs = ({ path: _path, backTo, onBack }: BreadcrumbsProps) => { const [_, navigate] = useLocation(); const location = window.location.pathname; const path = Array.isArray(_path) ? _path : [_path]; const loc = location.split("/").filter((v) => v !== ""); const hasBack = path.length > 1; const goBack = onBack ? onBack : useEvent(() => { if (backTo) { navigate(backTo, { replace: true }); return; } const href = loc.slice(0, path.length + 1).join("/"); navigate(`~/${href}`, { replace: true }); }); const crumbs = useMemo( () => path.map((p, key) => { const last = key === path.length - 1; const index = loc.indexOf(p); const href = loc.slice(0, index + 1).join("/"); const string = ucFirstAllSnakeToPascalWithSpaces(p); return { last, href, string, }; }), [path, loc], ); return (