<?php
header("Content-Type: application/json");
require_once "../config.php";  // adjust path if needed

$response = ["status" => "error", "message" => "Unknown error"];

try {
    // Fetch genders
    $sql = "SELECT gender_id, gender_name FROM tblgender ORDER BY gender_name ASC";
    $stmt = $dbh->prepare($sql);
    $stmt->execute();

    $genders = $stmt->fetchAll(PDO::FETCH_ASSOC);

    if ($genders && count($genders) > 0) {
        $response = [
            "status" => "success",
            "data"   => $genders
        ];
    } else {
        $response = [
            "status" => "error",
            "message" => "No genders found"
        ];
    }
} catch (Exception $e) {
    $response = [
        "status" => "error",
        "message" => $e->getMessage()
    ];
}

echo json_encode($response);
exit;
