<?php
// dashboard_awal/index.php
require_once "../admin/config.php";
$conn = connectDB(); // Create database connection

// Check for error messages
$error_message = '';
if (isset($_GET['error']) && $_GET['error'] == 'closed') {
    $error_message = 'Pendaftaran lomba telah ditutup oleh admin.';
} else if (isset($_GET['error']) && $_GET['error'] == 'unauthorized') {
    $error_message = 'Akses tidak sah! Silakan kembali ke halaman utama.';
} else if (isset($_GET['error']) && $_GET['error'] == 'session_expired') {
    $error_message = 'Sesi Anda telah berakhir. Silakan kembali ke halaman utama.';
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard FLS3N 2026</title>
    <link rel="shortcut icon" href="../assets/logoFLS3N.png" type="image/x-icon">
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
    <style>
        html, body {
            height: 100%;
            margin: 0;
            font-family: 'Poppins', sans-serif;
            background-color: #f8fafc;
            scroll-behavior: smooth;
        }

        .main-header {
            position: fixed;
            width: 100%;
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            background: rgba(157, 23, 77, 0.95);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: space-between;
            z-index: 10;
            top: 0;
            height: 80px;
            padding: 0 2rem;
            box-shadow: 0 4px 20px rgba(157, 23, 77, 0.3);
            transition: all 0.3s ease;
        }

        .main-header:hover {
            background: rgba(157, 23, 77, 1);
        }

        .logo-container {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .main-header .logo-container img {
            height: 65px;
            transition: transform 0.3s ease;
        }

        .main-header .logo-container img:hover {
            transform: scale(1.05);
        }

        .main-header .instansi-name {
            font-size: 26px;
            font-weight: 700;
            letter-spacing: 1px;
            background: linear-gradient(90deg, #fff, #f0abfc);
            background-clip: text;
            -webkit-text-fill-color: transparent;
            text-shadow: 0 2px 10px rgba(255, 255, 255, 0.2);
        }

        .page-container {
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }

        .content-wrapper {
            flex: 1;
            margin-top: 100px;
            padding: 2rem 0;
        }

        .hero-section {
            text-align: center;
            padding: 2rem 1rem 4rem;
            position: relative;
            overflow: hidden;
        }

        .hero-section::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: url('https://api.placeholder/1200/600') no-repeat center center;
            background-size: cover;
            opacity: 0.05;
            z-index: -1;
        }

        .hero-title {
            position: relative;
            display: inline-block;
            margin-bottom: 1.5rem;
        }

        .hero-title::after {
            content: "";
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 4px;
            background: linear-gradient(90deg, #9d174d, #db2777);
            border-radius: 4px;
        }

        .dashboard-cards {
            margin-top: 2rem;
        }

        .dashboard-card {
            background: white;
            border-radius: 16px;
            padding: 2rem;
            text-align: center;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
            transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;
            border: 1px solid rgba(0, 0, 0, 0.05);
            position: relative;
            overflow: hidden;
        }

        .dashboard-card::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 5px;
            transition: all 0.3s ease;
        }

        .dashboard-card.kota::before {
            background: linear-gradient(90deg, #ef4444, #f87171);
        }

        .dashboard-card.kabupaten::before {
            background: linear-gradient(90deg, #3b82f6, #60a5fa);
        }

        .dashboard-card.results::before {
            background: linear-gradient(90deg, #8b5cf6, #a78bfa);
        }

        .dashboard-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
        }

        .dashboard-card:hover::before {
            height: 10px;
        }

        .dashboard-card .icon-container {
            width: 160px;
            height: 160px;
            margin: 0 auto 1.5rem;
            padding: 1.5rem;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
        }

        .dashboard-card.kota .icon-container {
            background: linear-gradient(145deg, #fff5f5, #fee2e2);
            box-shadow: 0 10px 15px rgba(239, 68, 68, 0.15);
        }

        .dashboard-card.kabupaten .icon-container {
            background: linear-gradient(145deg, #eff6ff, #dbeafe);
            box-shadow: 0 10px 15px rgba(59, 130, 246, 0.15);
        }

        .dashboard-card.results .icon-container {
            background: linear-gradient(145deg, #f5f3ff, #ede9fe);
            box-shadow: 0 10px 15px rgba(139, 92, 246, 0.15);
        }

        .dashboard-card img {
            max-width: 100%;
            object-fit: contain;
            transition: transform 0.5s ease;
        }

        .dashboard-card:hover img {
            transform: scale(1.1);
        }

        .dashboard-card h2 {
            font-weight: 700;
            margin-bottom: 1rem;
            transition: all 0.3s ease;
        }

        .dashboard-card.kota h2 { color: #ef4444; }
        .dashboard-card.kabupaten h2 { color: #3b82f6; }
        .dashboard-card.results h2 { color: #8b5cf6; }

        .dashboard-card p {
            color: #64748b;
            margin-bottom: 1.5rem;
            font-size: 0.95rem;
            line-height: 1.6;
        }

        .btn-dashboard {
            padding: 0.75rem 2rem;
            border-radius: 50px;
            font-weight: 600;
            transition: all 0.3s ease;
            border: none;
            position: relative;
            overflow: hidden;
            z-index: 1;
            letter-spacing: 0.5px;
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
        }

        .btn-dashboard::after {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 0;
            height: 100%;
            z-index: -1;
            transition: all 0.3s ease;
            opacity: 0;
        }

        .btn-dashboard:hover::after {
            width: 100%;
            opacity: 1;
        }

        .btn-kota {
            background: linear-gradient(90deg, #ef4444, #f87171);
            color: white;
            box-shadow: 0 5px 15px rgba(239, 68, 68, 0.25);
        }

        .btn-kota::after { background: linear-gradient(90deg, #dc2626, #ef4444); }

        .btn-kabupaten {
            background: linear-gradient(90deg, #3b82f6, #60a5fa);
            color: white;
            box-shadow: 0 5px 15px rgba(59, 130, 246, 0.25);
        }

        .btn-kabupaten::after { background: linear-gradient(90deg, #2563eb, #3b82f6); }

        .btn-results {
            background: linear-gradient(90deg, #8b5cf6, #a78bfa);
            color: white;
            box-shadow: 0 5px 15px rgba(139, 92, 246, 0.25);
        }

        .btn-results::after { background: linear-gradient(90deg, #7c3aed, #8b5cf6); }

        .trophy-icon {
            font-size: 4rem;
            margin-bottom: 0.5rem;
            background: -webkit-linear-gradient(45deg, #ffd700, #f59e0b);
            background-clip: text;
            -webkit-text-fill-color: transparent;
            filter: drop-shadow(0 4px 6px rgba(245, 158, 11, 0.3));
            transition: all 0.3s ease;
        }

        footer {
            background: linear-gradient(90deg, #9d174d, #be185d);
            color: white;
            text-align: center;
            padding: 1.5rem 0;
            width: 100%;
            margin-top: auto;
            position: relative;
            box-shadow: 0 -5px 20px rgba(157, 23, 77, 0.2);
        }

        .status-badge {
            position: absolute;
            top: 1rem;
            right: 1rem;
            padding: 0.35rem 0.85rem;
            border-radius: 50px;
            font-size: 0.85rem;
            font-weight: 600;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            z-index: 5;
        }

        .status-badge.open { background: linear-gradient(90deg, #10b981, #34d399); color: white; }
        .status-badge.closed { background: linear-gradient(90deg, #ef4444, #f87171); color: white; }

        .disabled-btn {
            background: linear-gradient(90deg, #9ca3af, #d1d5db) !important;
            color: #f3f4f6;
            cursor: not-allowed;
            opacity: 0.7;
        }

        .closed-message {
            background: #fee2e2;
            border: 1px solid #fecaca;
            border-radius: 8px;
            padding: 0.75rem 1rem;
            margin-bottom: 1.5rem;
            color: #ef4444;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .toast-container { position: fixed; top: 100px; right: 20px; z-index: 1000; max-width: 350px; }
        .toast {
            background-color: #fff;
            color: #ef4444;
            padding: 15px 20px;
            border-radius: 8px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            border-left: 5px solid #ef4444;
            animation: slideInRight 0.5s forwards;
        }
        
        @keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
        @keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
    </style>
</head>
<body>
    <?php if (!empty($error_message)): ?>
    <div class="toast-container">
        <div class="toast" id="errorToast">
            <i class="fas fa-exclamation-circle"></i>
            <span><?php echo $error_message; ?></span>
            <span class="toast-close ml-auto" onclick="this.parentElement.remove()">&times;</span>
        </div>
    </div>
    <?php endif; ?>

    <div class="page-container">
        <header class="main-header">
            <div class="logo-container"> 
                <img src="../assets/tutwurii.png" alt="Logo">
                <img src="../assets/unisbank.png" alt="Logo">
                <img src="../assets/logoFLS3N.png" alt="Logo FLS3N">    
            </div>
            <div class="instansi-name">FLS3N 2026</div>
        </header>

        <div class="content-wrapper">
            <div class="container mx-auto px-4">
                <div class="hero-section animate__animated animate__fadeIn">
                    <h1 class="hero-title text-pink-600 font-bold text-4xl md:text-5xl text-center">DASHBOARD LOMBA FLS3N</h1>
                    <h2 class="text-gray-700 text-xl md:text-2xl font-medium text-center mb-3">SMA/MA/SMK/MAK/Sederajat TAHUN <?php echo date("Y"); ?></h2>
                    <p class="text-center text-gray-600 max-w-2xl mx-auto">Silahkan pilih domisili untuk melihat dan mendaftar pada cabang lomba yang tersedia. Festival dan Lomba Seni Siswa Nasional (FLS3N) merupakan ajang prestasi untuk mengembangkan bakat dan minat siswa.</p>
                </div>
                
                <div class="dashboard-cards">
                    <?php
                    $sql_kab_semarang = "SELECT status FROM status_lomba WHERE name = 'kabupaten_semarang'";
                    $sql_kab_demak = "SELECT status FROM status_lomba WHERE name = 'kabupaten_demak'";
                    $sql_kota_salatiga = "SELECT status FROM status_lomba WHERE name = 'kota_salatiga'";
                    $sql_pendaftaran_sekolah = "SELECT status FROM status_lomba WHERE name = 'pendaftaran_sekolah'";
                    
                    $kab_semarang_status = ($conn->query($sql_kab_semarang)->fetch_assoc())['status'] ?? 'closed';
                    $kab_demak_status = ($conn->query($sql_kab_demak)->fetch_assoc())['status'] ?? 'closed';
                    $kota_salatiga_status = ($conn->query($sql_kota_salatiga)->fetch_assoc())['status'] ?? 'closed';
                    $pendaftaran_sekolah_status = ($conn->query($sql_pendaftaran_sekolah)->fetch_assoc())['status'] ?? 'closed';

                    $pendaftaran_sekolah_open = ($pendaftaran_sekolah_status == 'open');
                    $all_closed = ($kab_semarang_status == 'closed' && $kab_demak_status == 'closed' && $kota_salatiga_status == 'closed');
                    ?>
                    
                    <?php if ($pendaftaran_sekolah_open): ?>
                        <div class="max-w-md mx-auto animate__animated animate__slideInUp">
                            <div class="dashboard-card" style="border-top: 5px solid #10b981;">
                                <span class="status-badge open">DIBUKA</span>
                                <div class="icon-container" style="background: linear-gradient(145deg, #f0fdf4, #dcfce7); box-shadow: 0 10px 15px rgba(16, 185, 129, 0.15);">
                                    <i class="fas fa-school" style="font-size: 3rem; color: #10b981;"></i>
                                </div>
                                <div>
                                    <h2 class="text-2xl md:text-3xl" style="color: #10b981;">Pendaftaran Sekolah</h2>
                                    <p>Daftarkan sekolah Anda untuk mengikuti Festival Lomba Seni Siswa Nasional (FLS3N) 2026. Lengkapi data sekolah dan upload bukti pendaftaran di BPTI.</p>
                                </div>
                                <a href="redirect-pendaftaran-sekolah.php" class="btn btn-dashboard" style="background: linear-gradient(90deg, #10b981, #34d399); color: white;">
                                    Daftar Sekolah <i class="fas fa-arrow-right"></i>
                                </a>
                            </div>
                        </div>
                    <?php elseif ($all_closed): ?>
                        <div class="bg-gradient-to-r from-red-50 to-pink-50 border border-red-200 rounded-xl p-6 mb-8 max-w-4xl mx-auto">
                            <div class="text-center">
                                <i class="fas fa-info-circle text-4xl text-red-500 mb-4"></i>
                                <h3 class="text-2xl font-bold text-red-700 mb-2">Pendaftaran Telah Ditutup</h3>
                                <p class="text-red-600 text-lg">Pendaftaran lomba FLS3N untuk semua domisili telah ditutup. Silakan cek hasil penilaian di bawah ini.</p>
                            </div>
                        </div>
                        <div class="max-w-md mx-auto animate__animated animate__slideInUp">
                            <div class="dashboard-card results">
                                <div class="icon-container">
                                    <i class="fas fa-trophy trophy-icon"></i>
                                </div>
                                <div>
                                    <h2 class="text-2xl md:text-3xl">Hasil & Pemenang Lomba</h2>
                                    <p>Lihat hasil penilaian dan daftar 10 pemenang terbaik dari setiap cabang lomba FLS3N.</p>
                                </div>
                                <a href="../hasil_penilaian" class="btn btn-dashboard btn-results">
                                    Lihat Pemenang <i class="fas fa-award"></i>
                                </a>
                            </div>
                        </div>
                    <?php else: ?>
                        <div class="grid grid-cols-1 md:grid-cols-3 gap-8 max-w-6xl mx-auto">
                            <div class="animate__animated animate__slideInUp" style="animation-delay: 0.2s">
                                <div class="dashboard-card kota <?php echo ($kab_semarang_status == 'closed') ? 'closed' : ''; ?>">
                                    <span class="status-badge <?php echo ($kab_semarang_status == 'closed') ? 'closed' : 'open'; ?>">
                                        <?php echo ($kab_semarang_status == 'closed') ? 'DITUTUP' : 'DIBUKA'; ?>
                                    </span>
                                    <div class="icon-container"><img src="../assets/kabupaten-semarang.png" alt="Semarang"></div>
                                    <h2 class="text-2xl">Kabupaten Semarang</h2>
                                    <p>Cabang lomba seni untuk domisili Kabupaten Semarang.</p>
                                    <?php if ($kab_semarang_status != 'closed'): ?>
                                        <a href="redirect-kab-semarang.php" class="btn btn-dashboard btn-kota">Masuk Dashboard <i class="fas fa-arrow-right"></i></a>
                                    <?php else: ?>
                                        <button class="btn btn-dashboard disabled-btn" disabled>DITUTUP <i class="fas fa-lock"></i></button>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <div class="animate__animated animate__slideInUp" style="animation-delay: 0.3s">
                                <div class="dashboard-card kabupaten <?php echo ($kab_demak_status == 'closed') ? 'closed' : ''; ?>">
                                    <span class="status-badge <?php echo ($kab_demak_status == 'closed') ? 'closed' : 'open'; ?>">
                                        <?php echo ($kab_demak_status == 'closed') ? 'DITUTUP' : 'DIBUKA'; ?>
                                    </span>
                                    <div class="icon-container"><img src="../assets/kabupaten-demak.png" alt="Demak"></div>
                                    <h2 class="text-2xl">Kabupaten Demak</h2>
                                    <p>Cabang lomba seni untuk domisili Kabupaten Demak.</p>
                                    <?php if ($kab_demak_status != 'closed'): ?>
                                        <a href="redirect-kab-demak.php" class="btn btn-dashboard btn-kabupaten">Masuk Dashboard <i class="fas fa-arrow-right"></i></a>
                                    <?php else: ?>
                                        <button class="btn btn-dashboard disabled-btn" disabled>DITUTUP <i class="fas fa-lock"></i></button>
                                    <?php endif; ?>
                                </div>
                            </div>

                            <div class="animate__animated animate__slideInUp" style="animation-delay: 0.4s">
                                <div class="dashboard-card kota <?php echo ($kota_salatiga_status == 'closed') ? 'closed' : ''; ?>">
                                    <span class="status-badge <?php echo ($kota_salatiga_status == 'closed') ? 'closed' : 'open'; ?>">
                                        <?php echo ($kota_salatiga_status == 'closed') ? 'DITUTUP' : 'DIBUKA'; ?>
                                    </span>
                                    <div class="icon-container"><img src="../assets/kota-salatiga.png" alt="Salatiga"></div>
                                    <h2 class="text-2xl">Kota Salatiga</h2>
                                    <p>Cabang lomba seni untuk domisili Kota Salatiga.</p>
                                    <?php if ($kota_salatiga_status != 'closed'): ?>
                                        <a href="redirect-kota-salatiga.php" class="btn btn-dashboard btn-kota">Masuk Dashboard <i class="fas fa-arrow-right"></i></a>
                                    <?php else: ?>
                                        <button class="btn btn-dashboard disabled-btn" disabled>DITUTUP <i class="fas fa-lock"></i></button>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        
        <footer class="bg-gradient-to-r from-pink-800 to-pink-700 text-white py-8">
            <div class="container mx-auto px-4">
                <div class="flex flex-col md:flex-row items-center justify-between">
                    <div class="flex flex-col items-center md:items-start mb-6 md:mb-0">
                        <div class="flex items-center gap-2 mb-4">
                            <img src="../assets/pkl.png" alt="Logo team" class="h-12">
                            <div class="text-xl font-bold">FTII Unisbank</div>
                        </div>
                        <p class="text-sm">&copy;<?php echo date("Y"); ?> FTII Unisbank. All rights reserved.</p>
                    </div>
                    <div class="text-center md:text-right">
                        <a href="https://www.unisbank.ac.id/v3/pmb-unisbank/" target="_blank" class="bg-blue-600 text-white px-5 py-3 rounded-full font-semibold shadow-lg inline-flex items-center gap-2">
                            <i class="fas fa-user-graduate"></i> PMB Unisbank
                        </a>
                    </div>
                </div>
            </div>
        </footer>
    </div>
</body>
</html>
<?php $conn->close(); ?>