<?php
// MASUKKAN API KEY BARU ANDA DI BAWAH INI
$api_key = 'AIzaSyB7-2jK0s7ddsAnCUWS9RoK5c3wWLL-bOw';

$url = 'https://generativelanguage.googleapis.com/v1beta/models?key=' . $api_key;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);

echo "<div style='font-family:sans-serif; padding: 20px;'>";
echo "<h2>Daftar Model AI yang Tersedia untuk Anda:</h2>";

if (isset($data['models'])) {
    echo "<table border='1' cellpadding='10' cellspacing='0' style='border-collapse: collapse;'>";
    echo "<tr style='background: #f1f5f9;'><th>Nama Model (Copy Ini)</th><th>Fungsi yang Didukung</th></tr>";
    
    foreach ($data['models'] as $model) {
        $nama = str_replace('models/', '', $model['name']);
        $fungsi = isset($model['supportedGenerationMethods']) ? implode(", ", $model['supportedGenerationMethods']) : 'Tidak ada';
        
        // Kita hanya mencari model yang mendukung "generateContent"
        if (strpos($fungsi, 'generateContent') !== false) {
            echo "<tr>";
            echo "<td><b style='color:blue;'>{$nama}</b></td>";
            echo "<td><span style='color:green;'>{$fungsi} ✅</span></td>";
            echo "</tr>";
        }
    }
    echo "</table>";
} else {
    echo "<p style='color:red;'>Error membaca data dari Google. Pastikan API Key benar.</p>";
    echo "<pre>"; print_r($data); echo "</pre>";
}
echo "</div>";
?>