const fs = require('fs');
let html = fs.readFileSync('index.html', 'utf8');

const services = [
  'ultrasound-scan',
  'blood-test',
  'digital-x-ray',
  'pregnancy-scan',
  'cardiac-package',
  'ecg',
  'echo',
  'pft',
  'allergy-test',
  'preventive-health-checkup'
];

let idx = 0;
html = html.replace(/<div class="location-grid">([\s\S]*?)<\/div>/g, (match, gridContent) => {
    let serviceSlug = services[idx++];
    let newGridContent = gridContent.replace(/<a href="[^"]*?" class="location-pill">(.*?)<\/a>/g, (m, locName) => {
        let locSlug = locName.toLowerCase().trim();
        return `<a href="${locSlug}/${serviceSlug}.html" class="location-pill">${locName}</a>`;
    });
    return `<div class="location-grid">${newGridContent}</div>`;
});

fs.writeFileSync('index.html', html);
console.log("Fixed main hub links!");
