const fs = require('fs');
const path = require('path');

const iconsDir = path.resolve(__dirname, '../assets/img/icons');
const iconFolder = path.resolve(__dirname, '../components/helpers');
const outputFile = path.resolve(iconFolder, 'bundleIcons.js');

const generateIconsBundle = () => {
  try {
    const files = fs.readdirSync(iconsDir);
    const components = files
      .filter((file) => file.endsWith('.svg')) // Only include .svg files
      .map((file) => {
        const name = path.basename(file, '.svg').toLowerCase()
          .split(/[^a-zA-Z0-9]+/) // Split by non-alphanumeric characters
          .map((word, index) =>
            index === 0
              ? word.charAt(0).toUpperCase() + word.slice(1) // Uppercase first word
              : word.charAt(0).toUpperCase() + word.slice(1) // Uppercase subsequent words
          )
          .join('');
        return `export { default as ${name} } from '@/assets/img/icons/${file}?component';`;
      });

    const bundleContent = components.join('\n');
    fs.writeFileSync(outputFile, bundleContent);
    console.log(`Icons bundle generated successfully at ${outputFile}`);
  } catch (error) {
    console.error('Error generating icons bundle:', error);
  }
};

generateIconsBundle();