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

async function convertSvgToPng(svgPath, pngPath, size) {
    try {
        const svgBuffer = fs.readFileSync(svgPath);
        
        await sharp(svgBuffer, {
            density: 300 // High DPI for better quality
        })
        .resize(size, size, {
            fit: 'contain',
            background: { r: 255, g: 255, b: 255, alpha: 0 } // Transparent background
        })
        .png()
        .toFile(pngPath);
        
        console.log(`✅ Created ${pngPath} (${size}x${size})`);
    } catch (error) {
        console.error(`❌ Error converting ${svgPath}:`, error.message);
    }
}

async function main() {
    const publicDir = path.join(__dirname, '..', 'public');
    
    // Convert logo.svg to various PNG sizes
    const logoPath = path.join(publicDir, 'logo.svg');
    if (fs.existsSync(logoPath)) {
        await convertSvgToPng(logoPath, path.join(publicDir, 'logo-512.png'), 512);
        await convertSvgToPng(logoPath, path.join(publicDir, 'logo-256.png'), 256);
        await convertSvgToPng(logoPath, path.join(publicDir, 'logo-128.png'), 128);
    }
    
    // Convert logo-large.svg to larger PNG sizes
    const logoLargePath = path.join(publicDir, 'logo-large.svg');
    if (fs.existsSync(logoLargePath)) {
        await convertSvgToPng(logoLargePath, path.join(publicDir, 'logo-1024.png'), 1024);
        await convertSvgToPng(logoLargePath, path.join(publicDir, 'logo-512.png'), 512);
    }
    
    console.log('\n✨ Logo conversion complete!');
}

main();

