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

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

import { useLokaliseTranslation } from 'src/utils/i18n';

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

const { key, titleTranslationKey } = itemsConfig.microloans;

const MICROLOANS_SECTION_PATH = '/microloans';

export type NavMicroloansProps = SidebarItemProps & {
  navPath: string;
};

const NavMicroloans = (props: NavMicroloansProps) => {
  const { isCollapsed, onClick, isActive: isActiveProp, navPath } = props;

  const { t } = useLokaliseTranslation('loans');
  const isActive = isActiveProp ?? getItemIsActive(MICROLOANS_SECTION_PATH);

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

export default NavMicroloans;
