<?php
header("Content-Type: application/xml; charset=utf-8");

require_once "admin/config/config.php";

/* ===============================
   STATIC URL LIST — EXACT COPY
=============================== */
$static_urls = [

["loc"=>"https://www.athenabhs.com/","changefreq"=>"daily","priority"=>"1.0"],

["loc"=>"https://www.athenabhs.com/doctor","changefreq"=>"weekly","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/our-team","changefreq"=>"weekly","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/clinical-therapist","changefreq"=>"weekly","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/psychologist","changefreq"=>"weekly","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/therapist","changefreq"=>"weekly","priority"=>"0.9"],

/* ===============================
   TREATMENT PAGES
=============================== */

["loc"=>"https://www.athenabhs.com/treatment/drug-addiction-treatment-center-in-gurgaon-delhi-ncr-india","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/treatment/alcohol-addiction-treatment-centre-in-delhi-gurgaon","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/treatment/best-panic-disorder-treatment-in-gurgaon","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/treatment/depression-treatment-centre-in-gurgaon","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/treatment/bipolar-disorder-rehab-center-in-gurgaon","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/treatment/borderline-personality-disorder-rehab-center-in-gurgaon","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/treatment/schizophrenia-treatment-in-delhi-gurgaon-ncr","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/treatment/top-ptsd-rehabilitation-center-in-gurgaon","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/treatment/ocd-treatment-centre-in-gurgaon","changefreq"=>"daily","priority"=>"0.9"],

/* ===============================
   FACILITY / BRAND PAGES
=============================== */

["loc"=>"https://www.athenabhs.com/athena-behavioral-health","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/athena-luxus","changefreq"=>"daily","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/best-psychiatric-and-mental-hospital-in-noida","changefreq"=>"daily","priority"=>"0.8"],
["loc"=>"https://www.athenabhs.com/athena-guwahati","changefreq"=>"daily","priority"=>"0.9"],

["loc"=>"https://www.athenabhs.com/athena-okas-facility","changefreq"=>"daily","priority"=>"0.9"],

/* ===============================
   COMPANY / INFO PAGES
=============================== */

["loc"=>"https://www.athenabhs.com/corporate","changefreq"=>"monthly","priority"=>"0.7"],
["loc"=>"https://www.athenabhs.com/about-us","changefreq"=>"monthly","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/media-center","changefreq"=>"weekly","priority"=>"0.8"],
["loc"=>"https://www.athenabhs.com/blog","changefreq"=>"daily","priority"=>"0.8"],
["loc"=>"https://www.athenabhs.com/contact","changefreq"=>"monthly","priority"=>"0.9"],
["loc"=>"https://www.athenabhs.com/careers","changefreq"=>"monthly","priority"=>"0.7"]


];

/* ===============================
   XML START
=============================== */

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

<?php

/* ===============================
   PRINT STATIC URLS
=============================== */

foreach ($static_urls as $url) {

echo "<url>";
echo "<loc>{$url['loc']}</loc>";
echo "<lastmod>".date("c")."</lastmod>";
echo "<changefreq>{$url['changefreq']}</changefreq>";
echo "<priority>{$url['priority']}</priority>";
echo "</url>";

}


/* ===============================
   BLOG URLs — DYNAMIC
=============================== */

/* ===============================
   BLOG URLs — DYNAMIC
=============================== */

$base_url = "https://www.athenabhs.com/";

$query = "
SELECT canonical_url, date
FROM blogs
WHERE canonical_url IS NOT NULL
AND canonical_url != ''
";

$result = mysqli_query($conn, $query);

while ($row = mysqli_fetch_assoc($result)) {

    $slug = trim($row['canonical_url']);

    // If already full URL, use as is. Otherwise prepend domain
    if (filter_var($slug, FILTER_VALIDATE_URL)) {
        $loc = $slug;
    } else {
        $loc = $base_url . ltrim($slug, '/');
    }

    $loc = htmlspecialchars($loc, ENT_QUOTES, 'UTF-8');
    $lastmod = date("c", strtotime($row['date']));

    echo "<url>";
    echo "<loc>$loc</loc>";
    echo "<lastmod>$lastmod</lastmod>";
    echo "<changefreq>monthly</changefreq>";
    echo "<priority>0.8</priority>";
    echo "</url>";
}


?>

</urlset>
