<?php
/**
 * API: Get Active Captains
 */

try {
    require_once dirname(__DIR__) . '/config.php';
    checkCashierAuth();

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

    // الحصول على الكباتن النشطين
    $sql = "SELECT id, name, phone FROM captains WHERE status = 'active' ORDER BY name";
    $result = $conn->query($sql);
    
    if (!$result) {
        throw new Exception($conn->error);
    }
    
    $captains = [];
    while ($row = $result->fetch_assoc()) {
        $captains[] = $row;
    }

    echo json_encode([
        'success' => true,
        'captains' => $captains
    ]);

} catch (Exception $e) {
    header('Content-Type: application/json');
    echo json_encode([
        'success' => false,
        'message' => 'خطأ في الخادم: ' . $e->getMessage(),
        'captains' => []
    ]);
}
?>