/**
 * Remove GTM bootstrap from proxied HTML on localhost so conversion pixels
 * (googleads.g.doubleclick.net) never fire and cannot break form handlers.
 */
export function stripLocalhostTrackers(html: string): string {
  let out = html;
  out = out.replace(
    /<script\b[^>]*googletagmanager\.js[^>]*>\s*<\/script>/gi,
    '<!-- gtm disabled on localhost -->',
  );
  out = out.replace(
    /<noscript>\s*<iframe\b[^>]*googletagmanager\.com[^>]*>\s*<\/iframe>\s*<\/noscript>/gi,
    '',
  );
  // reCAPTCHA cannot complete on localhost without keys / Google reachability
  out = out.replace(/recaptchaEnabled:\s*true/g, 'recaptchaEnabled: false');
  return out;
}
