<?php
// /htdocs/pages/api/cities.php

header('Content-Type: application/json');

$countryId = $_GET['country_id'] ?? 0;
if (!$countryId) {
    echo json_encode([]);
    exit;
}

$db = db();
$cities = $db->fetchAll(
    "SELECT id, name FROM cities WHERE country_id = ? AND is_active = 1 ORDER BY name",
    [$countryId]
);

echo json_encode($cities);