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

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

import useCustomServerTranslation from 'src/hooks/useCustomServerTranslation';
import { feedRoutes } from 'src/pages/dashboard/feed/routes';

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

const { key, titleTranslationKey } = itemsConfig.feed;

const PATH = feedRoutes.feed();
const MODULE = 'FEED';

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

  const { Icon } = useGetSidebarIcon({
    defaultIcon: IconSmartHome,
    key: 'Feed',
  });

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

  const isActive = isActiveProp ?? getItemIsActive(PATH);

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

export default NavFeedItem;
