import { Link, useRouterState } from "@tanstack/react-router"; import React, { FC } from 'react' import { BreadcrumbPage, Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerTrigger, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbSeparator, DrawerFooter, DrawerHeader, DrawerTitle, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, Button, SidebarObject, } from "@marzneshin/components" import { useScreenBreakpoint } from "@marzneshin/hooks/use-screen-breakpoint"; import { AppRouterPaths } from "@marzneshin/types"; import i18n from "@marzneshin/features/i18n"; interface Dir { href: AppRouterPaths; label: string; } interface NavigationDirectoryProps { sidebar: SidebarObject; } function getPathDirs(currentPath: string, sidebar: SidebarObject): Dir[] { const dirs: Dir[] = []; const pathArray = currentPath.split('/').filter(Boolean); // Split path and remove empty strings let fullPath = '/'; for (let i = 0; i < pathArray.length; i++) { const dir = pathArray[i]; fullPath += `/${dir}`; if (sidebar[dir]) { dirs.push({ href: sidebar[dir][0].to, label: sidebar[dir][0].title }); } else { dirs.push({ href: fullPath as AppRouterPaths, label: i18n.t(dir) }); } } return dirs; } const ITEMS_TO_DISPLAY = 3 export const NavigationDirectory: FC = ({ sidebar }) => { const [open, setOpen] = React.useState(false) const currentPath = useRouterState().location.pathname; const items = getPathDirs(currentPath, sidebar); const isDesktop = !useScreenBreakpoint("sm"); return ( {items.length > ITEMS_TO_DISPLAY ? ( <> {isDesktop ? ( {items.slice(1, -2).map((item, index) => ( {item.label} ))} ) : ( Navigate to Select a page to navigate to.
{items.slice(1, -2).map((item, index) => ( {item.label} ))}
)}
) : null} {items.slice(-ITEMS_TO_DISPLAY + 1).map((item, index) => ( {item.href ? ( <> {item.label} {index !== items.slice(-ITEMS_TO_DISPLAY + 1).length - 1 && } ) : ( {item.label} )} ))}
) }