<?php
require_once '../config/cors.php';
header('Content-Type: application/json');
require_once '../config/db.php';

try {
    $stmt = $pdo->query("SELECT id, area_name FROM areas ORDER BY LENGTH(area_name) ASC, area_name ASC");
    $areas = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode(['status' => 'success', 'data' => $areas]);
} catch (PDOException $e) {
    echo json_encode(['status' => 'success', 'data' => []]);
}
