import { FC } from 'react';

import {
  ICONS,
  IconsModules,
} from '@material-hu/components/design-system/Sidebar/constants';

import { useAuth } from 'src/contexts/JWTContext';
import { IconsStyle } from 'src/types/instance';

type Props = {
  defaultIcon: FC;
  key: IconsModules;
};

const useGetSidebarIcon = (props: Props) => {
  const { defaultIcon, key } = props;
  const {
    instance: { iconsStyle },
  } = useAuth();

  // Normalize underscores from iconsStyle
  const iconKey = iconsStyle?.replace('_', '').toLowerCase();

  let Icon = ICONS[iconKey]?.[key];
  if (iconsStyle === IconsStyle.ICONS || !Icon) Icon = defaultIcon;

  return { Icon, iconsStyle };
};

export default useGetSidebarIcon;
