import type { DraggableAttributes, DraggableSyntheticListeners, } from "@dnd-kit/core"; import { alpha, ListItem, ListItemButton, ListItemIcon, ListItemText, } from "@mui/material"; import type { CSSProperties, ReactNode } from "react"; import { useMatch, useNavigate, useResolvedPath } from "react-router"; import { useVerge } from "@/hooks/use-verge"; interface SortableProps { setNodeRef?: (element: HTMLElement | null) => void; attributes?: DraggableAttributes; listeners?: DraggableSyntheticListeners; style?: CSSProperties; isDragging?: boolean; disabled?: boolean; } interface Props { to: string; children: string; icon: ReactNode[]; sortable?: SortableProps; } export const LayoutItem = (props: Props) => { const { to, children, icon, sortable } = props; const { verge } = useVerge(); const { menu_icon } = verge ?? {}; const navCollapsed = verge?.collapse_navbar ?? false; const resolved = useResolvedPath(to); const match = useMatch({ path: resolved.pathname, end: true }); const navigate = useNavigate(); const effectiveMenuIcon = navCollapsed && menu_icon === "disable" ? "monochrome" : menu_icon; const { setNodeRef, attributes, listeners, style, isDragging, disabled } = sortable ?? {}; const draggable = Boolean(sortable) && !disabled; const dragHandleProps = draggable ? { ...(attributes ?? {}), ...(listeners ?? {}) } : undefined; return ( { const bgcolor = mode === "light" ? alpha(primary.main, 0.15) : alpha(primary.main, 0.35); const color = mode === "light" ? "#1f1f1f" : "#ffffff"; return { "&.Mui-selected": { bgcolor }, "&.Mui-selected:hover": { bgcolor }, "&.Mui-selected .MuiListItemText-primary": { color }, }; }, ]} title={navCollapsed ? children : undefined} aria-label={navCollapsed ? children : undefined} onClick={() => navigate(to)} > {(effectiveMenuIcon === "monochrome" || !effectiveMenuIcon) && ( {icon[0]} )} {effectiveMenuIcon === "colorful" && ( {icon[1]} )} ); };