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

// Read the CSV file
const csvPath = path.join(__dirname, 'icons.csv');
const csvContent = fs.readFileSync(csvPath, 'utf8');

// Parse CSV lines
const lines = csvContent.split('\n').filter(line => line.trim());
const header = lines[0];
const dataLines = lines.slice(1);

// Icon names - replace these with your actual icon names after reviewing them
const iconNames = [
    // Add your icon names here, one for each row
    // Example: "hamburger", "pizza", "drink", etc.
    // For now, placeholders:
    "icon_1", "icon_2", "icon_3", "icon_4", "icon_5", "icon_6", "icon_7", "icon_8", "icon_9", "icon_10",
    "icon_11", "icon_12", "icon_13", "icon_14", "icon_15", "icon_16", "icon_17", "icon_18", "icon_19", "icon_20",
    "icon_21", "icon_22", "icon_23", "icon_24", "icon_25", "icon_26", "icon_27", "icon_28", "icon_29", "icon_30",
    "icon_31", "icon_32", "icon_33", "icon_34", "icon_35", "icon_36", "icon_37", "icon_38", "icon_39", "icon_40",
    "icon_41", "icon_42", "icon_43", "icon_44", "icon_45", "icon_46", "icon_47", "icon_48", "icon_49", "icon_50",
    "icon_51", "icon_52", "icon_53", "icon_54", "icon_55", "icon_56", "icon_57", "icon_58", "icon_59", "icon_60",
    "icon_61", "icon_62", "icon_63", "icon_64", "icon_65", "icon_66", "icon_67", "icon_68", "icon_69", "icon_70",
    "icon_71", "icon_72", "icon_73", "icon_74", "icon_75", "icon_76", "icon_77", "icon_78", "icon_79", "icon_80",
    "icon_81", "icon_82", "icon_83", "icon_84", "icon_85", "icon_86", "icon_87", "icon_88", "icon_89", "icon_90",
    "icon_91", "icon_92", "icon_93", "icon_94", "icon_95", "icon_96", "icon_97", "icon_98", "icon_99", "icon_100",
    "icon_101", "icon_102", "icon_103", "icon_104", "icon_105", "icon_106", "icon_107", "icon_108", "icon_109", "icon_110",
    "icon_111", "icon_112", "icon_113", "icon_114", "icon_115", "icon_116", "icon_117", "icon_118", "icon_119", "icon_120",
    "icon_121", "icon_122", "icon_123", "icon_124", "icon_125", "icon_126", "icon_127", "icon_128", "icon_129", "icon_130",
    "icon_131", "icon_132", "icon_133", "icon_134", "icon_135", "icon_136", "icon_137", "icon_138"
];

// Validate that we have the right number of names
if (iconNames.length !== dataLines.length) {
    console.error(`Error: You provided ${iconNames.length} icon names but there are ${dataLines.length} data rows in the CSV.`);
    process.exit(1);
}

// Create new CSV content with icon names
const newLines = [header];

dataLines.forEach((line, index) => {
    // Remove trailing comma if present and add the icon name
    const cleanLine = line.replace(/,$/, '');
    newLines.push(`${cleanLine},"${iconNames[index]}"`);
});

// Write the updated CSV
const newCsvContent = newLines.join('\n');
fs.writeFileSync(csvPath, newCsvContent, 'utf8');

console.log(`✅ Successfully added ${iconNames.length} icon names to icons.csv`);
console.log('📁 File saved:', csvPath);

// Show summary
const namedCount = iconNames.filter(name => name && !name.startsWith('icon_')).length;
console.log(`📊 ${namedCount} custom names, ${iconNames.length - namedCount} placeholder names`);
