/**
 * Copy Toast UI Editor dist files to frontend vendor folder.
 * Run after npm install: node tools/copy-toast-ui-editor.js
 */
const fs = require('fs');
const path = require('path');

const root = path.resolve(__dirname, '..');
const srcDir = path.join(root, 'node_modules', '@toast-ui', 'editor', 'dist');
const destDir = path.join(root, 'src', 'frontend', 'vendor', 'toast-ui');

if (!fs.existsSync(srcDir)) {
  console.warn('@toast-ui/editor not found. Run npm install first.');
  process.exit(1);
}

fs.mkdirSync(destDir, { recursive: true });

const files = ['toastui-editor.css', 'toastui-editor.js'];
for (const f of files) {
  const src = path.join(srcDir, f);
  const dest = path.join(destDir, f);
  if (fs.existsSync(src)) {
    fs.copyFileSync(src, dest);
    console.log('Copied', f);
  } else {
    // try .min version
    const minName = f.replace('.css', '.min.css').replace('.js', '.min.js');
    const srcMin = path.join(srcDir, minName);
    if (fs.existsSync(srcMin)) {
      fs.copyFileSync(srcMin, path.join(destDir, minName));
      console.log('Copied', minName);
    } else {
      console.warn('Not found:', src, 'or', srcMin);
    }
  }
}
