// Bulk brand sweep: Shield → takedowns
const fs = require('fs');
const path = require('path');
const dir = 'public/views';
const files = fs.readdirSync(dir).filter(f => f.endsWith('.html'));
let changedFiles = 0;
const replacements = [
  // Title separators
  [/&mdash;\s*Shield\b/g, '&mdash; takedowns'],
  [/ — Shield\b/g, ' — takedowns'],
  // Body: "Shield is / Shield helps / Shield will / etc"
  [/>Shield\s+(is|helps|provides|does|will|can|doesn|never|requires|uses|stores|offers|tracks|serves|removes|generates|drafts|dispatches|is built|is operated|is dedicated|prioritizes)\b/g, '>takedowns $1'],
  // Inline brand mentions
  [/>Shield<\/a>/g, '>takedowns</a>'],
  [/>Shield<\/span>/g, '>takedowns</span>'],
  [/>Shield<\/h1>/g, '>takedowns</h1>'],
  [/>Shield<\/h2>/g, '>takedowns</h2>'],
  [/>Shield<\/h3>/g, '>takedowns</h3>'],
  [/>Shield<\/h4>/g, '>takedowns</h4>'],
  [/>Shield<\/p>/g, '>takedowns</p>'],
  [/>Shield<\/button>/g, '>takedowns</button>'],
  [/>Shield<\/div>/g, '>takedowns</div>'],
  [/>Shield<\/title>/g, '>takedowns</title>'],
  // Meta tags
  [/"author"\s+content="Shield"/g, '"author" content="takedowns"'],
  [/property="og:site_name"\s+content="Shield"/g, 'property="og:site_name" content="takedowns by vesamuni"'],
  [/"site_name":\s*"Shield"/g, '"site_name": "takedowns by vesamuni"'],
  [/"name":\s*"Shield"/g, '"name": "takedowns"'],
  [/"name":\s*"About Shield"/g, '"name": "About takedowns"'],
  [/"name":\s*"Shield for individuals"/g, '"name": "takedowns for individuals"'],
  [/"name":\s*"Shield for survivors"/g, '"name": "takedowns for survivors"'],
  [/"alternateName":\s*"Shield[^"]*"/g, '"alternateName": "takedowns by vesamuni"'],
  [/content="Shield"/g, 'content="takedowns"'],
  // JSON-LD descriptions
  [/"description":\s*"Shield is /g, '"description": "takedowns is '],
  [/"description":\s*"Acceptable use policy for Shield\."/g, '"description": "Acceptable use policy for takedowns."'],
  [/"name":\s*"Acceptable Use Policy"\s*\+\s*" — Shield"/g, '"name": "Acceptable Use Policy" + " — takedowns"'],
  // Trailing mentions in lists
  [/\bShield\b(?=\s+will never)/g, 'takedowns'],
  [/\bShield\b(?=\s+operates)/g, 'takedowns'],
  [/\bShield\b(?=\s+prioritizes)/g, 'takedowns'],
  // Lowercase
  [/>Shield</g, '>takedowns<'],
];
for (const f of files) {
  const fp = path.join(dir, f);
  let html = fs.readFileSync(fp, 'utf8');
  const before = html;
  for (const [pattern, repl] of replacements) {
    html = html.replace(pattern, repl);
  }
  if (html !== before) {
    fs.writeFileSync(fp, html);
    changedFiles++;
  }
}
console.log('Changed', changedFiles, 'files in this pass');
