<?php
require_once __DIR__ . '/../includes/functions.php';
header('Content-Type: application/json; charset=utf-8');
$iso2 = strtoupper(trim((string)($_GET['iso2'] ?? '')));
if (!preg_match('/^[A-Z]{2}$/', $iso2)) {
    echo json_encode(['ok'=>false,'message'=>'Invalid country code']);
    exit;
}
$country = country_by_iso2($iso2);
if (!$country) {
    echo json_encode(['ok'=>false,'message'=>'Country not enabled']);
    exit;
}
echo json_encode([
    'ok' => true,
    'id' => (int)$country['id'],
    'iso2' => $country['iso2'],
    'name' => $country['name'],
    'slug' => $country['slug'],
    'url' => country_path($country)
]);
