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

const iconsDir = path.resolve(__dirname, '../assets/img/icons');
const outputFile = path.resolve(__dirname, '../assets/icons.json');

const generateIconsJson = () => {
  try {
    const files = fs.readdirSync(iconsDir);
    const icons = files
      .filter((file) => file.endsWith('.svg')) // Only include .svg files
      .map((file) => ({
        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(''), // Extract the name without extension
      }));

    fs.writeFileSync(outputFile, JSON.stringify(icons, null, 2));
    console.log(`Icons JSON generated successfully at ${outputFile}`);
  } catch (error) {
    console.error('Error generating icons JSON:', error);
  }
};

generateIconsJson();