import { Icon as IconTest } from 'lucide-react';
import clsx from 'clsx';
import { MouseEventHandler, PropsWithChildren } from 'react';
import { AutomationTestingProps } from '@/types';
import { Icon } from '@@/Icon';
import { useSidebarState } from '../useSidebarState';
import { Wrapper } from './Wrapper';
import { SidebarTooltip } from './SidebarTooltip';
import { useSidebarSrefActive } from './useSidebarSrefActive';
interface Props extends AutomationTestingProps {
icon?: IconTest;
to: string;
params?: object;
label: string;
isSubMenu?: boolean;
ignorePaths?: string[];
includePaths?: string[];
}
export function SidebarItem({
icon,
to,
params,
label,
isSubMenu = false,
ignorePaths = [],
includePaths = [],
'data-cy': dataCy,
}: Props) {
const { isOpen } = useSidebarState();
const anchorProps = useSidebarSrefActive(to, undefined, params, undefined, {
ignorePaths,
includePaths,
});
const sidebarAnchor = (
{!!icon && svg]:w-4')} />}
{(isOpen || isSubMenu) && {label}}
);
if (isOpen || isSubMenu) return sidebarAnchor;
return (
{label}
}
>
{sidebarAnchor}
);
}
type ItemAnchorProps = {
href?: string;
onClick: MouseEventHandler;
className: string;
isOpen: boolean;
isSubMenu: boolean;
dataCy?: string;
};
function ItemAnchor({
href,
onClick,
className,
isOpen,
isSubMenu,
dataCy,
children,
}: PropsWithChildren) {
return (
{children}
);
}