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

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

import useCustomServerTranslation from 'src/hooks/useCustomServerTranslation';
import { useTasksNotifications } from 'src/pages/dashboard/employeeLifecycle/hooks/useTasksNotifications';
import { employeeLifecycleRoutes } from 'src/pages/dashboard/employeeLifecycle/routes';

import itemsConfig from '../constants';
import { SidebarItemProps } from '../types';
import { getItemIsActive } from '../utils';

const PATH = employeeLifecycleRoutes.tasks.base();
const { key, titleTranslationKey } = itemsConfig.tasks;

const NavTasksItem = ({
  isCollapsed,
  onClick,
  isActive: isActiveProp,
}: SidebarItemProps) => {
  const title = useCustomServerTranslation({
    module: 'TASKS',
    defaultTranslationKey: titleTranslationKey,
    namespace: 'dashboard_sidebar_app',
  });

  const isActive = isActiveProp ?? getItemIsActive(PATH);

  const { notifications } = useTasksNotifications();

  return (
    <HuSidebarNavItem
      key={key}
      depth={0}
      title={title}
      icon={<IconClipboardList />}
      path={PATH}
      info={{ isNew: true, notificationCount: notifications }}
      isCollapsed={isCollapsed}
      onClick={onClick}
      active={isActive}
    />
  );
};

export default NavTasksItem;
