// This should not be imported
import { IconSchool } from '@material-hu/icons/tabler';

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

import { TENARIS_ID } from 'src/constants/scorm';
import { useAuth } from 'src/contexts/JWTContext';
import { scormRoutes } from 'src/pages/dashboard/scorm/routes';
import { useLokaliseTranslation } from 'src/utils/i18n';

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

import('src/pages/dashboard/scorm/i18n');

const { key, titleTranslationKey } = itemsConfig.scorm;

const PATH = scormRoutes.all();

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

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

  const title =
    instance?.id === TENARIS_ID
      ? t('SCORM:TENARIS_COURSES')
      : t(titleTranslationKey);

  const isActive = isActiveProp ?? getItemIsActive(PATH);

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

export default NavScormItem;
