<?php
include 'ser.php';
$config = include 'config.php';
$expiration_config = include 'expiration_config.php';

// --- CONFIG AUDIO (Ganti Link Musik Di Sini) ---
$music_url = "https://files.catbox.moe/oxu82t.mp3"; 
// ----------------------------------------------

if ($expiration_config && isset($expiration_config['expiration_datetime'])) {
    $expiration_date_str = $expiration_config['expiration_datetime'];
    if (!empty($expiration_date_str)) {
        try {
            $expiration_datetime = new DateTime($expiration_date_str);
            $current_time = new DateTime();
            if ($current_time > $expiration_datetime) {
                header('Location: exp.php');
                exit;
            }
        } catch (Exception $e) {}
    }
}

$nik = isset($nik) ? $nik : 'Manggwanzz User';
$sender = isset($sender) ? $sender : 'sender@manggwanzz.io';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Admin Levy Hosting - Panel</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Rajdhani:wght@300;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
    
    <style>
        :root {
            --primary-neon: #00f2ff;
            --accent-red: #ff003c;
            --accent-yellow: #ffea00;
            --accent-blue: #004cff;
            --dark-bg: #0a0a0a;
        }

        body {
            font-family: 'Rajdhani', sans-serif;
            background: var(--dark-bg);
            color: #fff;
            min-height: 100vh;
            overflow-x: hidden;
            /* Latar belakang dibuat lebih terang dengan opasitas 0.7 */
            background-image: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.7)), url('https://files.catbox.moe/ktcy7r.jpg');
            background-size: cover;
            background-position: center;
            background-attachment: fixed;
        }

        /* --- EFEK CAHAYA LATAR BELAKANG --- */
        .bg-glow {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 600px;
            height: 600px;
            background: radial-gradient(circle, rgba(0, 242, 255, 0.15) 0%, rgba(0, 0, 0, 0) 70%);
            z-index: 0;
            pointer-events: none;
            animation: pulse-bg 5s infinite alternate;
        }

        @keyframes pulse-bg {
            from { opacity: 0.5; transform: translate(-50%, -50%) scale(1); }
            to { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
        }

        #particles-js { position: fixed; width: 100%; height: 100%; z-index: 1; top: 0; left: 0; pointer-events: none; }

        .main-container { max-width: 900px; margin: auto; padding: 40px 20px; position: relative; z-index: 10; }

        .glass-card {
            background: rgba(255, 255, 255, 0.05);
            backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.15);
            border-radius: 25px;
            padding: 35px;
            margin-bottom: 30px;
            box-shadow: 0 15px 45px rgba(0,0,0,0.6);
        }

        /* --- LOGO DIPERBESAR & CAHAYA --- */
        .logo-img {
            width: 150px; height: 150px; border-radius: 50%; object-fit: cover;
            border: 4px solid var(--primary-neon);
            box-shadow: 0 0 30px var(--primary-neon), 0 0 60px rgba(0, 242, 255, 0.3);
            animation: floating-glow 3s ease-in-out infinite;
        }

        @keyframes floating-glow {
            0%, 100% { transform: translateY(0px) rotate(0deg); box-shadow: 0 0 20px var(--primary-neon); }
            50% { transform: translateY(-15px) rotate(2deg); box-shadow: 0 0 50px var(--primary-neon); }
        }

        /* --- NAMA PANEL WARNA-WARNI & RAPAT --- */
        .main-title {
            font-family: 'Orbitron', sans-serif; 
            font-size: 1.8rem; 
            letter-spacing: 2px; /* Spasi dikurangi */
            text-transform: uppercase;
            font-weight: 800;
            margin-top: 15px;
            /* Gradient Putih, Kuning, Merah, Biru */
            background: linear-gradient(to right, #ffffff, var(--accent-yellow), var(--accent-red), var(--primary-neon));
            -webkit-background-clip: text; 
            -webkit-text-fill-color: transparent;
            filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.2));
        }

        .form-control {
            background: rgba(0, 0, 0, 0.6) !important; border: 1px solid rgba(255, 255, 255, 0.2);
            color: #00f2ff !important; border-radius: 12px; font-family: 'Orbitron', sans-serif;
        }

        .btn-cyber { border: none; padding: 12px; border-radius: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 2px; transition: 0.4s; }
        .btn-update { background: linear-gradient(45deg, #007bff, #00f2ff); color: white; width: 100%; box-shadow: 0 0 15px rgba(0, 123, 255, 0.4); }
        .btn-add { background: linear-gradient(45deg, #ff003c, #ff8000); color: white; box-shadow: 0 0 15px rgba(255, 0, 60, 0.4); }

        .music-control {
            position: fixed; bottom: 30px; right: 30px; z-index: 1000;
            background: rgba(255, 255, 255, 0.1); backdrop-filter: blur(15px);
            border: 1px solid var(--primary-neon); padding: 12px 25px; border-radius: 50px; 
            display: flex; align-items: center; box-shadow: 0 0 20px rgba(0, 242, 255, 0.3);
        }
        
        #playBtn {
            border: none; background: var(--primary-neon); color: #000;
            width: 40px; height: 40px; display: flex; align-items: center;
            justify-content: center; border-radius: 50%; margin-left: 15px;
        }

        .badge-limit { background: var(--accent-red); padding: 5px 12px; border-radius: 6px; font-family: 'Orbitron'; box-shadow: 0 0 10px rgba(255,0,60,0.5); }
    </style>
</head>
<body>

<div class="bg-glow"></div>
<audio id="myAudio" loop>
  <source src="audio/gokil.mp3" type="audio/mpeg">
</audio>

<div class="music-control">
    <span class="small font-weight-bold text-white" style="letter-spacing: 1px;">SYSTEM AUDIO</span>
    <button onclick="togglePlay()" id="playBtn">
        <i class="fas fa-play" id="iconPlay"></i>
    </button>
</div>

<div id="particles-js"></div>

<div class="main-container animate__animated animate__fadeIn">
    
    <div class="brand-header text-center mb-5">
        <img src="https://files.catbox.moe/00u7lm.jpg" class="logo-img" alt="Logo">
        <h1 class="main-title">PANEL LEVY HOSTING</h1>
        <p class="text-white-50 small" style="letter-spacing: 5px;">PREMIUM INTERFACE VVIP V4.8</p>
    </div>

    <div class="row">
        <div class="col-md-6">
            <div class="glass-card">
                <h5 class="mb-4 small" style="color: var(--primary-neon); font-family: 'Orbitron';"><i class="fas fa-microchip mr-2"></i> DATA SERVER</h5>
                <div class="form-group">
                    <label class="small text-muted">NAMA RESULT</label>
                    <input type="text" id="namaResult" class="form-control" value="<?= htmlspecialchars($nik); ?>">
                </div>
                <div class="form-group">
                    <label class="small text-muted">SENDER IDENTITY</label>
                    <input type="text" id="panelMurni" class="form-control" value="<?= htmlspecialchars($sender); ?>" readonly style="opacity: 0.6;">
                </div>
                <button id="gantiButton" class="btn btn-cyber btn-update">
                    <i class="fas fa-sync-alt mr-1"></i> UPDATE DATA SYSTEM
                </button>
            </div>
        </div>

        <div class="col-md-6">
            <div class="glass-card">
                <h5 class="mb-4 small" style="color: var(--accent-red); font-family: 'Orbitron';"><i class="fas fa-user-shield mr-2"></i> EMAIL CONFIG</h5>
                <div class="form-group">
                    <label class="small text-muted">TARGET EMAIL</label>
                    <input type="email" id="email" class="form-control" placeholder="example@gmail.com">
                </div>
                <div class="form-group">
                    <label class="small text-muted">LIMIT RESULT</label>
                    <input type="number" id="jumlahResult" class="form-control" value="155">
                </div>
                <button id="addEmailButton" class="btn btn-cyber btn-add w-100">
                    <i class="fas fa-plus-circle mr-1"></i> ADD NEW EMAIL
                </button>
            </div>
        </div>
    </div>

    <div class="glass-card">
        <h5 class="mb-4 text-center small" style="font-family: 'Orbitron'; letter-spacing: 4px; color: var(--accent-yellow);">DAFTAR DATABASE EMAIL</h5>
        <div class="table-responsive">
            <table class="table table-borderless text-white">
                <thead style="border-bottom: 2px solid rgba(0, 242, 255, 0.2);">
                    <tr style="color: var(--primary-neon); font-size: 0.8rem;">
                        <th>EMAIL ADDRESS</th>
                        <th class="text-center">LIMIT</th>
                        <th class="text-center">ACTION</th>
                    </tr>
                </thead>
                <tbody id="emailData" style="font-size: 0.9rem;"></tbody>
            </table>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script>

<script>
    var audio = document.getElementById("myAudio");
    var iconPlay = document.getElementById("iconPlay");

    function togglePlay() {
        if (audio.paused) {
            audio.play();
            iconPlay.className = 'fas fa-pause';
        } else {
            audio.pause();
            iconPlay.className = 'fas fa-play';
        }
    }

    // --- CONFIG PARTICLES LEBIH BESAR & JELAS ---
    particlesJS('particles-js', {
        "particles": {
            "number": { "value": 120, "density": { "enable": true, "value_area": 800 } },
            "color": { "value": ["#00f2ff", "#ffffff", "#ffea00"] },
            "shape": { "type": "circle" },
            "opacity": { "value": 0.6, "random": true },
            "size": { "value": 6, "random": true }, /* Ukuran partikel diperbesar */
            "line_linked": { "enable": true, "distance": 140, "color": "#00f2ff", "opacity": 0.3, "width": 1.5 },
            "move": { "enable": true, "speed": 4, "direction": "none", "random": true, "out_mode": "out" }
        }
    });

    document.getElementById('gantiButton').addEventListener('click', function() {
        const nick = document.getElementById('namaResult').value;
        const sender = document.getElementById('panelMurni').value;
        fetch(`ganti.php?nick=${encodeURIComponent(nick)}&sender=${encodeURIComponent(sender)}`)
        .then(() => {
            Swal.fire({ 
                icon: 'success', 
                title: 'SUCCESS!', 
                text: 'Data Sistem Berhasil Diperbarui',
                background: '#0a0a0a', 
                color: '#fff',
                confirmButtonColor: '#00f2ff'
            });
        });
    });

    document.getElementById('addEmailButton').addEventListener('click', function() {
        const email = document.getElementById('email').value;
        const limit = document.getElementById('jumlahResult').value;
        if(!email) return;
        const fd = new FormData();
        fd.append('email', email);
        fd.append('jumlahResult', limit);
        fetch('add.php', { method: 'POST', body: fd }).then(() => { 
            fetchEmails(); 
            document.getElementById('email').value = '';
            Swal.fire({
                icon: 'success', title: 'BERHASIL!', text: 'Email Ditambahkan ke Database',
                confirmButtonColor: '#00f2ff', background: '#0a0a0a', color: '#fff'
            });
        });
    });

    function fetchEmails() {
        fetch('data.php').then(res => res.json()).then(data => {
            const body = document.getElementById('emailData');
            body.innerHTML = '';
            data.forEach(item => {
                body.innerHTML += `
                    <tr>
                        <td class="align-middle"><i class="fas fa-envelope mr-2 text-info"></i>${item.email}</td>
                        <td class="text-center align-middle"><span class="badge-limit">${item.jumlahResult}</span></td>
                        <td class="text-center align-middle">
                            <button class="btn btn-sm text-danger" onclick="deleteEmail('${item.email}')"><i class="fas fa-trash-alt"></i></button>
                        </td>
                    </tr>`;
            });
        });
    }

    function deleteEmail(email) {
        fetch('delete.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
            body: `email=${encodeURIComponent(email)}`
        }).then(() => fetchEmails());
    }

    window.onload = fetchEmails;
</script>

</body>
</html>