import * as FaIcons from 'react-icons/fa';
import * as Fa6Icons from 'react-icons/fa6';

const DEFAULT_ICONS = [
  'FaReact',
  'FaNodeJs',
  'FaPython',
  'FaJava',
  'FaHtml5',
  'FaCss3Alt',
  'FaJs',
  'FaDocker',
  'FaGithub',
  'FaDatabase',
  'FaCode',
  'FaAngular',
  'FaVuejs',
  'FaAws',
  'FaGoogle',
  'FaMicrosoft',
  'FaApple',
  'FaLinux',
  'FaWindows',
  'FaBriefcase',
  'FaGraduationCap',
  'FaAward',
  'FaTrophy',
  'FaChartLine',
  'FaUsers',
  'FaUserTie',
  'FaLaptopCode',
  'FaMobileAlt',
  'FaNetworkWired',
];

export const defaultIcons = DEFAULT_ICONS.reduce(
  (acc, iconName) => {
    const IconComponent = FaIcons[iconName as keyof typeof FaIcons] || Fa6Icons[iconName as keyof typeof Fa6Icons];
    if (IconComponent) {
      acc[iconName] = <IconComponent className='w-full h-full' />;
    }
    return acc;
  },
  {} as { [key: string]: JSX.Element }
);

export const getFilteredIcons = (searchTerm: string): { [key: string]: JSX.Element } => {
  if (!searchTerm || searchTerm.length < 2) return defaultIcons;

  const search = searchTerm.toLowerCase();
  const filteredIcons: { [key: string]: JSX.Element } = {};

  Object.keys({ ...FaIcons, ...Fa6Icons }).forEach((iconName) => {
    if (iconName.toLowerCase().includes(search)) {
      const IconComponent = FaIcons[iconName as keyof typeof FaIcons] || Fa6Icons[iconName as keyof typeof Fa6Icons];
      filteredIcons[iconName] = <IconComponent className='w-full h-full' />;
    }
  });

  return filteredIcons;
};
