#!/usr/bin/env node
// Palette swap: imperium-website-renders warm-cream palette -> brand-v5 greens/neutrals.
// Usage: node rebrand.mjs <file.html> [...more]
import { readFileSync, writeFileSync } from 'node:fs';

const HEX = [
  ['#F7F4EE', '#F4F1EA'], // old bone -> Bone
  ['#FDFCF9', '#F9F8F3'], ['#FDFCF8', '#F9F8F3'],           // panel near-whites -> sage-neutral panel
  ['#FBF9F4', '#F8F7F2'], ['#FCF9F3', '#F8F7F2'],
  ['#F9F6F0', '#F6F5EF'], ['#FAF7F1', '#F7F6F1'],           // -> Paper
  ['#F5F1E8', '#F0F2EA'], ['#F3EFE7', '#EFF1E9'], ['#F0EDE6', '#ECF0E6'],
  ['#EFE9DC', '#E7EDDF'], ['#EDE7DA', '#E4EBDC'],           // gradient deep edges -> sage
  ['#E2DACB', '#DCE4D6'],                                    // bezel metal edge -> sage metal
  ['#1B1A17', '#15130E'],                                    // ink
  ['#C4AD96', '#4CB782'], ['#B79C7F', '#3FA085'],           // champagne -> mint / bali
  ['#8C4A3C', '#E23A28'],                                    // brick -> Ember
];
const RGBA = [
  [/rgba\(\s*27\s*,\s*26\s*,\s*23\s*,/g, 'rgba(21, 19, 14,'],
  [/rgba\(\s*196\s*,\s*173\s*,\s*150\s*,/g, 'rgba(76, 183, 130,'],
  [/rgba\(\s*183\s*,\s*156\s*,\s*127\s*,/g, 'rgba(63, 160, 133,'],
  [/rgba\(\s*140\s*,\s*74\s*,\s*60\s*,/g, 'rgba(226, 58, 40,'],
  [/rgba\(\s*224\s*,\s*216\s*,\s*201\s*,/g, 'rgba(214, 226, 210,'],
];
const FONT = [
  [/font-family:\s*'Inter'[^;]*;/g, "font-family: 'Switzer', sans-serif;"],
  [/'InterLocal'/g, "'Switzer'"],
];

for (const f of process.argv.slice(2)) {
  let s = readFileSync(f, 'utf8');
  const before = s;
  for (const [from, to] of HEX) s = s.replace(new RegExp(from, 'gi'), to);
  for (const [re, to] of RGBA) s = s.replace(re, to);
  for (const [re, to] of FONT) s = s.replace(re, to);
  if (s !== before) { writeFileSync(f, s); console.log('rebranded', f); }
  else console.log('unchanged', f);
}
