import { Fragment, ReactNode } from 'react';
import { Link, useLocation } from 'react-router-dom';
import { cn } from '@crux-kit/utils';
import { MenuItem } from '#app/config/types';
import { useMenuConfig } from '#app/menu';
import { useMenu } from '#shared/hooks/useMenu';
import { Container } from '#shared/widgets/common/Container';
export interface ToolbarHeadingProps {
title?: string | ReactNode;
description?: string | ReactNode;
}
function Toolbar({ children }: { children?: ReactNode }) {
return (
{children}
);
}
function ToolbarActions({ children }: { children?: ReactNode }) {
return {children}
;
}
function ToolbarBreadcrumbs() {
const menuConfig = useMenuConfig();
const { pathname } = useLocation();
const { getBreadcrumb, isActive } = useMenu(pathname);
const items: MenuItem[] = getBreadcrumb(menuConfig);
if (items.length === 0) {
return null;
}
return (
{items.map((item, index) => {
const isLast = index === items.length - 1;
const active = item.path ? isActive(item.path) : false;
return (
{item.path ? (
{item.title}
) : (
{item.title}
)}
{!isLast && /}
);
})}
);
}
const ToolbarHeading = ({ title = '' }: ToolbarHeadingProps) => {
const { pathname } = useLocation();
const { getCurrentItem } = useMenu(pathname);
const menuConfig = useMenuConfig();
const item = getCurrentItem(menuConfig);
return (
{title || item?.title}
);
};
export { Toolbar, ToolbarActions, ToolbarBreadcrumbs, ToolbarHeading };