<?php
// --- KONFIGURASI ---
$agent_code = "therock77";
$agent_token = "5177a82fd3f96b8c86eae75942666e0e";
$apiUrl = "https://api.nexusggr.com";

// --- PERSIAPAN REQUEST ---
$postArray = [
    "method" => "provider_list",
    "agent_code" => $agent_code,
    "agent_token" => $agent_token
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postArray));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);

$res = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);

// --- TAMPILAN ---
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title>Daftar Provider NGAMING</title>
    <style>
        body { font-family: sans-serif; margin: 20px; }
        table { border-collapse: collapse; width: 100%; border: 1px solid #ccc; }
        th, td { padding: 12px; border: 1px solid #ddd; text-align: left; }
        th { background-color: #f4f4f4; }
        .status-1 { color: green; font-weight: bold; }
        .error { color: red; }
    </style>
</head>
<body>

    <h2>Daftar Provider Game</h2>

    <?php if ($error): ?>
        <p class="error">Terjadi kesalahan koneksi: <?php echo $error; ?></p>
    <?php else: ?>
        <?php 
            $data = json_decode($res, true);
            if (isset($data['providers']) && is_array($data['providers'])): 
        ?>
            <table>
                <thead>
                    <tr>
                        <th>No</th>
                        <th>Kode</th>
                        <th>Nama Provider</th>
                        <th>Tipe</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($data['providers'] as $i => $p): ?>
                    <tr>
                        <td><?php echo $i + 1; ?></td>
                        <td><?php echo $p['code']; ?></td>
                        <td><?php echo $p['name']; ?></td>
                        <td><?php echo $p['type']; ?></td>
                        <td class="status-1"><?php echo $p['status'] == 1 ? 'Aktif' : 'Nonaktif'; ?></td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php else: ?>
            <p>Data tidak ditemukan. Respon: <?php echo htmlspecialchars($res); ?></p>
        <?php endif; ?>
    <?php endif; ?>

</body>
</html>