import { IconBooks } from '@material-hu/icons/tabler';

import SidebarNavItem from '@material-hu/components/design-system/Sidebar/components/NavItem';

import useLibrariesTitle from 'src/pages/dashboard/HuLibraries/hooks/useLibrariesTitle';
import { huLibrariesRoutes } from 'src/pages/dashboard/HuLibraries/routes';

import itemsConfig from '../constants';
import useGetSidebarIcon from '../hooks/useSidebarIcon';
import { type SidebarItemProps } from '../types';
import { getItemIsActive } from '../utils';

const PATH = huLibrariesRoutes.base();

const NavLibraryItem = (props: SidebarItemProps) => {
  const { isCollapsed, onClick, isActive: isActiveProp } = props;

  const title = useLibrariesTitle();

  const { Icon } = useGetSidebarIcon({
    defaultIcon: IconBooks,
    key: 'Knowledge Libraries',
  });

  const isActive = isActiveProp ?? getItemIsActive(PATH);

  return (
    <SidebarNavItem
      key={itemsConfig.knowledgeLibraries.key}
      depth={0}
      title={title}
      icon={<Icon />}
      path={PATH}
      isCollapsed={isCollapsed}
      onClick={onClick}
      active={isActive}
    />
  );
};

export default NavLibraryItem;
