const fs = require('fs');
const content = fs.readFileSync('dist/assets/index-D9sWWWv_.js', 'utf8');

const targetStr = 'Generate kode voucher';
const idx = content.indexOf(targetStr);
const segment = content.substring(idx - 10000, idx + 1000);

// Let's find "onSubmit" before "Generate kode voucher"
const onSubIdx = segment.lastIndexOf('onSubmit:');
if (onSubIdx !== -1) {
  const handlerName = segment.substring(onSubIdx + 9, segment.indexOf(',', onSubIdx));
  console.log("Handler name found:", handlerName);
  
  // Find where this handlerName is declared
  const searchDecl = `const ${handlerName}=` ;
  const declIdx = content.indexOf(searchDecl);
  if (declIdx !== -1) {
    console.log("Found declaration of", handlerName, "at", declIdx);
    console.log(content.substring(declIdx - 200, declIdx + 3000));
  } else {
    // try with space
    const searchDecl2 = `const ${handlerName} =`;
    const declIdx2 = content.indexOf(searchDecl2);
    if (declIdx2 !== -1) {
      console.log("Found declaration of", handlerName, "at", declIdx2);
      console.log(content.substring(declIdx2 - 200, declIdx2 + 3000));
    } else {
      console.log("Could not find declaration of", handlerName);
    }
  }
} else {
  console.log("Could not find onSubmit");
}
