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

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

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

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

const PATH = employeeLifecycleRoutes.onboardings();
const { key, titleTranslationKey } = itemsConfig.employeeLifecycle;

const NavEmployeeLifecycleItem = ({
  isCollapsed,
  onClick,
  isActive: isActiveProp,
}: SidebarItemProps) => {
  const { Icon } = useGetSidebarIcon({
    defaultIcon: IconDoor,
    key: 'Employee Lifecycle',
  });

  const title = useCustomServerTranslation({
    module: 'EMPLOYEE_LIFECYCLE',
    defaultTranslationKey: titleTranslationKey,
    namespace: 'dashboard_sidebar_app',
  });

  const { notifications } = useOnboardingsNotifications();

  const isActive = isActiveProp ?? getItemIsActive(PATH);

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

export default NavEmployeeLifecycleItem;
