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

// Configuration
const PUBLIC_DIR = path.join(__dirname, '..', 'public');
const OUT_DIR = path.join(__dirname, '..', 'out');
const FILES_TO_COPY = ['.htaccess', 'web.config'];

// Ensure out directory exists
if (!fs.existsSync(OUT_DIR)) {
    console.warn('⚠ out directory does not exist. Make sure "next build" (static export) has run.');
    process.exit(1);
}

FILES_TO_COPY.forEach(filename => {
    const source = path.join(PUBLIC_DIR, filename);
    const destination = path.join(OUT_DIR, filename);

    try {
        if (fs.existsSync(source)) {
            fs.copyFileSync(source, destination);
            console.log(`✓ ${filename} copied to out directory`);
        } else {
            console.warn(`⚠ ${filename} not found in public directory`);
        }
    } catch (error) {
        console.error(`Error copying ${filename}:`, error.message);
        process.exit(1);
    }
});
