const fs = require('fs');
const path = require('path');

const locations = [
  { slug: 'porur', name: 'Porur', nearby: 'Karambakkam, Mugalivakkam' },
  { slug: 'kundrathur', name: 'Kundrathur', nearby: 'Kovur, Mangadu' },
  { slug: 'gerugambakkam', name: 'Gerugambakkam', nearby: 'Kolapakkam, Porur' },
  { slug: 'ramapuram', name: 'Ramapuram', nearby: 'Porur, K K Nagar' },
  { slug: 'iyyappanthangal', name: 'Iyyappanthangal', nearby: 'Kattupakkam, Numbal' },
  { slug: 'mugalivakkam', name: 'Mugalivakkam', nearby: 'Ramapuram, Manapakkam' },
  { slug: 'kolapakkam', name: 'Kolapakkam', nearby: 'Gerugambakkam, Manapakkam' },
  { slug: 'anakaputhur', name: 'Anakaputhur', nearby: 'Pammal, Pallavaram' },
  { slug: 'thiruverkadu', name: 'Thiruverkadu', nearby: 'Maduravoyal, Poonamallee' },
  { slug: 'kattupakkam', name: 'Kattupakkam', nearby: 'Iyyappanthangal, Poonamallee' },
  { slug: 'maduravoyal', name: 'Maduravoyal', nearby: 'Nerkundram, Vanagaram' },
];

const services = [
  { slug: 'ultrasound-scan', name: 'Ultrasound Scan', lowerName: 'ultrasound scan', img: '../../Assets/ultrasound.png',
    desc: (loc) => `If you are looking for a highly reliable and clear ultrasound scan in ${loc.name}, Chennai, David Labs and Scans is your trusted diagnostic destination. We utilize the latest state-of-the-art sonography equipment to provide high-resolution imaging for abdominal, pelvic, and general body evaluations. Our experienced radiologists ensure that every ultrasound scan near ${loc.name} is conducted with the utmost care, prioritizing patient comfort and clinical accuracy. With affordable pricing, minimal waiting times, and detailed reports delivered swiftly, we help your consulting physician make well-informed healthcare decisions without any diagnostic delay.`
  },
  { slug: 'blood-test', name: 'Blood Test', lowerName: 'blood test', img: '../../Assets/blood-testing.png',
    desc: (loc) => `For absolutely accurate and affordable blood tests in ${loc.name}, Chennai, David Labs offers a comprehensive, advanced pathology lab setup. From routine complete blood counts (CBC), diabetes screening, and thyroid profiles to complex biochemical evaluations, our NABL-accredited diagnostic laboratory guarantees the highest level of precision. When searching for a blood test lab near ${loc.name}, patients trust us for our rigorously hygienic sample collection process and exceptionally fast turnaround times. Getting your routine lab work done is now completely hassle-free, delivering dependable and verified reports right on time.`
  },
  { slug: 'digital-x-ray', name: 'Digital X-Ray', lowerName: 'digital x-ray', img: '../../Assets/X-ray.png',
    desc: (loc) => `Experience fast, highly detailed, and low-radiation digital X-ray services right here in ${loc.name}, Chennai at David Labs and Scans. Whether you need a chest X-ray, joint imaging, or orthopedic bone scans, our advanced digital radiography machines capture precisely detailed internal images instantly. Choosing our center for a digital X-ray near ${loc.name} means you get immediate processing and digitally enhanced clarity that significantly aids in accurate orthopedic or pulmonary diagnostics. We maintain a completely safe, sterile environment while ensuring rapid results.`
  },
  { slug: 'pregnancy-scan', name: 'Pregnancy Scan', lowerName: 'pregnancy scan', img: '../../Assets/pregnancy-scans.png',
    desc: (loc) => `Expecting mothers seeking a safe, comfortable, and accurate pregnancy scan in ${loc.name}, Chennai can confidently rely on David Labs and Scans. We understand that maternal care requires a delicate touch, and our specialized imaging technology provides crystal-clear fetal monitoring, growth tracking, and anomaly screening scans. By choosing our dedicated fetal assessment services near ${loc.name}, you are assured of detailed consultations with experienced professionals. We prioritize your privacy and peace of mind by offering thoroughly detailed visual reports that capture every crucial milestone of your baby's development.`
  },
  { slug: 'cardiac-package', name: 'Cardiac Package', lowerName: 'cardiac package', img: '../../Assets/Cardiac-Package.png',
    desc: (loc) => `Take proactive control of your heart health with our comprehensive cardiac package in ${loc.name}, Chennai. Heart disease prevention starts with thorough screening, and David Labs and Scans brings together the most critical diagnostic cardiovascular tests into one highly affordable bundle. Evaluating your cardiovascular wellness near ${loc.name} has never been easier; our full package covers lipid profiling, structural heart imaging, and electrical rhythm tests. We empower our patients with a totally unified, in-depth cardiac risk assessment to catch potential issues early and keep their hearts beating strong.`
  },
  { slug: 'ecg', name: 'ECG', lowerName: 'ecg', img: '../../Assets/ECG.png',
    desc: (loc) => `Monitor your heart’s electrical activity instantly with a precision ECG in ${loc.name}, Chennai at David Labs and Scans. An electrocardiogram is a fundamental first step in evaluating chest pain, palpitations, or general rhythmic irregularities. Our clinical technicians are experts at conducting comfortable and completely painless ECG tests near ${loc.name}, ensuring completely accurate tracing of your heart’s rhythm. The fast procedure provides immediate printout results, giving your cardiologist the vital data they need instantly.`
  },
  { slug: 'echo', name: 'ECHO', lowerName: 'echo', img: '../../Assets/Echocardiogram.png',
    desc: (loc) => `David Labs and Scans offers state-of-the-art echocardiogram (ECHO) testing in ${loc.name}, Chennai to evaluate your heart's structural integrity and pumping strength. Using advanced, non-invasive ultrasound waves, we map your heart valves and chambers in real-time. Patients looking for an ECHO near ${loc.name} choose us for our highly detailed cardiovascular scans and specialized reporting. This crucial structural analysis helps physicians accurately diagnose conditions like heart failure, valve disease, or congenital abnormalities without any invasive procedures.`
  },
  { slug: 'pft', name: 'PFT', lowerName: 'pft', img: '../../Assets/PFT.png',
    desc: (loc) => `Assess your lung health and respiratory strength with our advanced Pulmonary Function Test (PFT) in ${loc.name}, Chennai. Whether you are dealing with asthma, chronic bronchitis, or general shortness of breath, David Labs and Scans provides highly sensitive spirometry equipment. Getting a reliable PFT near ${loc.name} is essential for measuring your total lung capacity and airflow correctly. Our trained staff will safely guide you through the breathing exercises to ensure the diagnostic readings are perfectly reflective of your actual pulmonary capability.`
  },
  { slug: 'allergy-test', name: 'Allergy Test', lowerName: 'allergy test', img: '../../Assets/allergy-testing.png',
    desc: (loc) => `Identify exactly what is triggering your symptoms with a comprehensive, accurate allergy test in ${loc.name}, Chennai. At David Labs and Scans, we offer extensive panel testing for food, dust, dander, and environmental allergens using state-of-the-art pathology. By booking your detailed allergy test near ${loc.name}, you eliminate the guesswork behind chronic sneezing, skin rashes, or digestive discomfort. We deliver extremely comprehensive reporting that allows you and your doctor to construct a reliable, long-term defensive treatment plan.`
  },
  { slug: 'preventive-health-checkup', name: 'Preventive Health Checkup', lowerName: 'preventive health checkup', img: '../../Assets/Preventive-Health-Checkup.png',
    desc: (loc) => `Invest in your long-term wellness with an affordable, full-body preventive health checkup in ${loc.name}, Chennai. David Labs and Scans has meticulously designed screening packages that evaluate all major organ functions—from liver and kidney health to diabetes and cholesterol levels. Undergoing a robust master health checkup near ${loc.name} gives you total peace of mind by catching underlying issues long before they become serious symptoms. Fast, private, and exceptionally thorough, our preventive profiles are the cornerstone of a healthier, happier life.`
  },
];

const template = (loc, srv) => {
  // Generate other locations pills
  const otherLocations = locations.filter(l => l.slug !== loc.slug).map(l => 
    `<a href="../${l.slug}/${srv.slug}.html" class="location-pill">${l.name}</a>`
  ).join('\n                        ');

  // Generate other services pills
  const otherServices = services.filter(s => s.slug !== srv.slug).map(s => 
    `<a href="./${s.slug}.html" class="location-pill">${s.name}</a>`
  ).join('\n                        ');

  return `<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>${srv.name} in ${loc.name}, Chennai | David Labs and Scans</title>
    <meta name="description" content="Get an accurate and affordable ${srv.lowerName} at David Labs and Scans in ${loc.name}, Chennai. NABL accredited diagnostic center accessible from ${loc.nearby}.">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700;800&display=swap" rel="stylesheet">
    <script src="https://unpkg.com/@phosphor-icons/web"></script>
    <link rel="stylesheet" href="../styles.css">
</head>
<body>
    <header>
        <div class="nav-container">
            <a href="/" class="brand-placeholder">
                <i class="ph-fill ph-cross"></i> David Labs <span>& Scans</span>
            </a>
            <a href="#" class="book-btn">BOOK A TEST</a>
        </div>
    </header>

    <section class="hero style-sub" style="padding: 4rem 2rem;">
        <h1>${srv.name} in <span>${loc.name}</span>, Chennai</h1>
    </section>

    <main class="container">
        
        <!-- Section 1: Specific Service Location -->
        <section class="content-section">
            <div class="content-text">
                <h2>${srv.name} in ${loc.name}, Chennai</h2>
                <p>Our center is highly accessible from <b>${loc.nearby}</b>, making it easy to schedule your visit with zero hassle.</p>
                <p>${srv.desc(loc)}</p>
            </div>
            <div class="image-option">
                <img src="${srv.img}" alt="${srv.name} near ${loc.name}">
            </div>
        </section>

        <!-- Section 2: Why David Labs / Lower Cost -->
        <section class="content-section reverse">
            <div class="image-option">
                <img src="../../Assets/affordability.jpg" alt="Affordable Pricing">
            </div>
            <div class="content-text">
                <h2>Why does David Scans & Labs offer services at low prices?</h2>
                <p>We focus on efficiency, high patient volume, and optimized operations to reduce cost without compromising quality.</p>
                
                <h2>How does David Scans and Labs offer Services at a lower cost?</h2>
                <p>Using automation and scale, we reduce cost per test and deliver fast, accurate reports.</p>
            </div>
        </section>

        <!-- Section 3: General Diagnostics Information -->
        <section class="content-section">
            <div class="content-text">
                <h2>David Labs and Scans</h2>
                <p>David Labs and Scans is a trusted diagnostic center in Chennai offering accurate, reliable, and affordable medical testing services with NABL-accredited standards and advanced equipment.</p>
                
                <h2>Our Diagnostic Specialities</h2>
                <p>We provide a wide range of diagnostic services across Chennai.</p>
            </div>
            <div class="image-option">
                <img src="../../Assets/equipment.jpg" alt="Diagnostic Equipment">
            </div>
        </section>

        <!-- Internal Linking Grid -->
        <section class="service-grid-wrapper" style="margin-top: 4rem; padding-top: 3rem; border-top: 1px solid var(--border);">
            <div class="service-grid-header">
                <h2>Other Locations for ${srv.name}</h2>
            </div>
            <div class="location-grid" style="margin-bottom: 3rem; justify-content: center;">
                ${otherLocations}
            </div>
            
            <div class="service-grid-header">
                <h2>Other Services in ${loc.name}</h2>
            </div>
            <div class="location-grid" style="justify-content: center;">
                ${otherServices}
            </div>
        </section>
    </main>

    <footer style="margin-top: 4rem; text-align: center; padding: 2rem; border-top: 1px solid var(--border); background-color: var(--card-bg);">
        <p style="color: var(--text-muted);">&copy; 2026 David Labs and Scans. All Rights Reserved.</p>
    </footer>
</body>
</html>`;
};

locations.forEach(loc => {
  const dir = path.join(__dirname, loc.slug);
  fs.mkdirSync(dir, { recursive: true });
  services.forEach(srv => {
    fs.writeFileSync(path.join(dir, `${srv.slug}.html`), template(loc, srv));
  });
});

console.log("Successfully generated all 110 pages!");
