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

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

import { timeTrackingRoutes } from 'src/pages/dashboard/timeTracking/routes';
import { useLokaliseTranslation } from 'src/utils/i18n';

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

const { key, titleTranslationKey } = itemsConfig.timeTracking;

const PATH = timeTrackingRoutes.collaborators();

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

  const { t } = useLokaliseTranslation('dashboard_sidebar_app');

  const { Icon } = useGetSidebarIcon({
    defaultIcon: IconCalendarClock,
    key: 'Time tracking',
  });

  const isActive = isActiveProp ?? getItemIsActive(PATH);

  return (
    <HuSidebarNavItem
      key={key}
      depth={0}
      title={t(titleTranslationKey)}
      icon={<Icon />}
      path={PATH}
      isCollapsed={isCollapsed}
      onClick={onClick}
      active={isActive}
    />
  );
};

export default NavTimeTrackingItem;
