#!/usr/bin/env node
import { copyFileSync, mkdirSync, readdirSync, statSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const srcDir = join(__dirname, '..', 'src', 'ui');
const distDir = join(__dirname, '..', 'dist', 'ui');

function copyDir(src, dest) {
  mkdirSync(dest, { recursive: true });
  
  const entries = readdirSync(src);
  
  for (const entry of entries) {
    const srcPath = join(src, entry);
    const destPath = join(dest, entry);
    
    if (statSync(srcPath).isDirectory()) {
      copyDir(srcPath, destPath);
    } else if (entry.endsWith('.tsx') || entry.endsWith('.jsx')) {
      copyFileSync(srcPath, destPath);
    }
  }
}

try {
  console.log('Copying React apps to dist...');
  copyDir(srcDir, distDir);
  console.log('Assets copied successfully');
} catch (error) {
  console.error('Error copying assets:', error);
  process.exit(1);
}
