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

// Define the CSS files to bundle in order
const cssFiles = [
  'static/assets/plugins/bootstrap/bootstrap.min.css',
  'static/assets/css/theme.css'
];

// Output file
const outputFile = 'static/assets/css/bundle.min.css';

// Function to bundle CSS files
function bundleCSS() {
  let bundledCSS = '';
  
  console.log('Starting CSS bundling...');
  
  cssFiles.forEach(file => {
    const filePath = path.join(__dirname, '..', file);
    console.log(`Processing: ${filePath}`);
    
    if (fs.existsSync(filePath)) {
      const content = fs.readFileSync(filePath, 'utf8');
      bundledCSS += `\n/* === ${file} === */\n${content}\n`;
      console.log(`✓ Added: ${file}`);
    } else {
      console.warn(`⚠ Warning: ${file} not found`);
    }
  });
  
  // Ensure output directory exists
  const outputDir = path.dirname(outputFile);
  if (!fs.existsSync(outputDir)) {
    fs.mkdirSync(outputDir, { recursive: true });
  }
  
  // Write bundled CSS
  fs.writeFileSync(path.join(__dirname, '..', outputFile), bundledCSS);
  console.log(`✓ Bundled CSS saved to: ${outputFile}`);
}

// Run the bundling
bundleCSS();
