/**
 * Test webpack module loading issue
 * This script tests if the config imports are causing the webpack error
 */

const path = require('path');

console.log('Testing module imports...\n');

try {
  console.log('1. Testing health types import...');
  const healthTypes = require('./lib/types/health');
  console.log('✓ Health types loaded successfully');
  console.log('  - Exports:', Object.keys(healthTypes).length > 0 ? Object.keys(healthTypes) : 'Type definitions only');
} catch (err) {
  console.error('✗ Health types failed:', err.message);
}

try {
  console.log('\n2. Testing config index import...');
  const config = require('./lib/config/index.ts');
  console.log('✓ Config loaded successfully');
  console.log('  - UI keys:', Object.keys(config.UI || {}));
} catch (err) {
  console.error('✗ Config failed:', err.message);
  console.error('  Stack:', err.stack);
}

try {
  console.log('\n3. Testing English translations import...');
  const { en } = require('./lib/config/translations/en.ts');
  console.log('✓ English translations loaded');
  console.log('  - Has dir:', en && en.dir);
  console.log('  - Has t:', en && typeof en.t === 'object');
  console.log('  - Keys count:', en && en.t ? Object.keys(en.t).length : 0);

  // Check if status translations exist
  if (en && en.t && en.t.status) {
    console.log('  - Status translations:', Object.keys(en.t.status).slice(0, 5).join(', '), '...');
  } else {
    console.error('  ✗ Missing status translations!');
  }
} catch (err) {
  console.error('✗ English translations failed:', err.message);
  console.error('  Stack:', err.stack);
}

try {
  console.log('\n4. Testing Arabic translations import...');
  const { ar } = require('./lib/config/translations/ar.ts');
  console.log('✓ Arabic translations loaded');
  console.log('  - Keys count:', ar && ar.t ? Object.keys(ar.t).length : 0);
} catch (err) {
  console.error('✗ Arabic translations failed:', err.message);
}

console.log('\n5. Checking translation file sizes...');
const fs = require('fs');
const enSize = fs.statSync('./lib/config/translations/en.ts').size;
const arSize = fs.statSync('./lib/config/translations/ar.ts').size;
console.log(`  - en.ts: ${(enSize / 1024).toFixed(2)} KB`);
console.log(`  - ar.ts: ${(arSize / 1024).toFixed(2)} KB`);

if (enSize > 500000 || arSize > 500000) {
  console.log('\n⚠️  WARNING: Translation files are very large (>500KB)');
  console.log('   This may cause webpack bundling issues in client components');
  console.log('   Consider splitting translations or lazy loading them');
}

console.log('\n✓ All tests completed');
