<?php
declare(strict_types=1);

require_once __DIR__ . "/../config/db.php";
require_once __DIR__ . "/../config/auth.php";


header('Content-Type: application/json; charset=utf-8');

$district_id = strtoupper(trim((string)($_GET['district_id'] ?? '')));
if ($district_id === '') { echo json_encode([]); exit; }

try {
    $st = $pdo->prepare("SELECT id, name FROM blocks WHERE district_id=? ORDER BY name ASC");
    $st->execute([$district_id]);
    echo json_encode($st->fetchAll(), JSON_UNESCAPED_UNICODE);
} catch (Throwable $e) {
    http_response_code(500);
    echo json_encode(["error" => "blocks_failed", "district_id" => $district_id]);
}
