#!/usr/bin/env node

// Parse the component registry and verify files exist
const fs = require('fs');
const path = require('path');

// Read the registry
const registryPath = '/home/overbits/dss/admin-ui/js/config/component-registry.js';
const registryContent = fs.readFileSync(registryPath, 'utf-8');

// Extract all component definitions
const componentMatches = registryContent.match(/'([^']+)':\s*\(\)\s*=>\s*import\('([^']+)'\)/g);

let components = [];
let missing = [];

if (componentMatches) {
  componentMatches.forEach(match => {
    const [, tagName, importPath] = match.match(/'([^']+)':\s*\(\)\s*=>\s*import\('([^']+)'\)/);
    const fullPath = path.join('/home/overbits/dss/admin-ui/js', importPath + '.js');

    components.push({
      tag: tagName,
      importPath: importPath,
      fullPath: fullPath,
      exists: fs.existsSync(fullPath)
    });

    if (!fs.existsSync(fullPath)) {
      missing.push({ tag: tagName, path: fullPath });
    }
  });
}

console.log(`\n📊 COMPONENT REGISTRY VALIDATION\n`);
console.log(`Total Registered: ${components.length}`);
console.log(`Files Found: ${components.filter(c => c.exists).length}`);
console.log(`Files Missing: ${missing.length}\n`);

if (missing.length > 0) {
  console.log(`❌ MISSING COMPONENTS:\n`);
  missing.forEach(m => {
    console.log(`  - ${m.tag}`);
    console.log(`    Expected: ${m.path}`);
  });
  console.log('');
}

console.log(`✅ EXISTING COMPONENTS (${components.filter(c => c.exists).length}):\n`);
components.filter(c => c.exists).forEach(c => {
  console.log(`  ✓ ${c.tag}`);
});
