const fs = require('fs');

const files = [
  'dist/assets/index-D9sWWWv_.js',
  'dist/server.cjs'
];

const keywords = [
  'Simulasi',
  'simulasi',
  'Simulasi Bayar',
  'Simulasi Bayar Sukses',
  'Simulasi Transaksi Realtime',
  'simulated',
  'dummy'
];

files.forEach(file => {
  if (!fs.existsSync(file)) {
    console.log(`File ${file} does not exist.`);
    return;
  }
  const content = fs.readFileSync(file, 'utf8');
  console.log(`=== Searching in ${file} (Size: ${content.length} chars) ===`);
  keywords.forEach(kw => {
    let idx = 0;
    let occurrences = [];
    while ((idx = content.indexOf(kw, idx)) !== -1) {
      occurrences.push(idx);
      idx += kw.length;
    }
    console.log(`Keyword "${kw}": found ${occurrences.length} times`);
    if (occurrences.length > 0) {
      console.log(`Offsets:`, occurrences.slice(0, 10));
      // Print first occurrence snippet
      const firstIdx = occurrences[0];
      const start = Math.max(0, firstIdx - 150);
      const end = Math.min(content.length, firstIdx + 150);
      console.log(`Snippet of first match at offset ${firstIdx}:`);
      console.log(content.substring(start, end));
      console.log('--------------------------------------------------');
    }
  });
});
