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

function walk(dir) {
  let results = [];
  fs.readdirSync(dir).forEach((file) => {
    const full = path.join(dir, file);
    if (fs.statSync(full).isDirectory()) {
      results = results.concat(walk(full));
    } else if (/\.(tsx|ts|css)$/.test(file)) {
      results.push(full);
    }
  });
  return results;
}

const files = walk('src');
let violations = 0;

files.forEach((f) => {
  const lines = fs.readFileSync(f, 'utf8').split('\n');
  lines.forEach((l, i) => {
    if (/\bshadow-(sm|md|lg|xl|2xl)\b/.test(l)) {
      console.log(`SHADOW: ${f}:${i + 1} -> ${l.trim()}`);
      violations++;
    }
    if (/\brounded-(full|lg|md|xl|2xl|3xl)\b/.test(l)) {
      console.log(`ROUNDED: ${f}:${i + 1} -> ${l.trim()}`);
      violations++;
    }
    if (/\bbg-gradient\b/.test(l)) {
      console.log(`GRADIENT: ${f}:${i + 1} -> ${l.trim()}`);
      violations++;
    }
    if (/box-shadow:/.test(l)) {
      console.log(`BOX-SHADOW: ${f}:${i + 1} -> ${l.trim()}`);
      violations++;
    }
  });
});

console.log('--- VERIFICATION RESULT ---');
console.log('TOTAL_VIOLATIONS:', violations);
if (violations === 0) {
  console.log('VERIFICATION_PASSED: 0 residual style violations across src/');
  process.exit(0);
} else {
  console.log('VERIFICATION_FAILED');
  process.exit(1);
}
