<?php
$page_title = "Events | Swarnawahini"; 
require_once '../config.php';
require '../components/db_connect.php';

// Logic to fetch events
$stmt = $conn->query("SELECT * FROM events ORDER BY created_at DESC");
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $page_title; ?></title>
    
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
    
    <style>
        /* --- GLOBAL STYLES FROM DESIGN --- */
        body {
            font-family: 'Poppins', sans-serif;
            background: rgb(25, 52, 134); /* Exact background color from */
            color: white;
            min-height: 100vh;
            padding-top: 90px; /* Header spacing */
            padding-bottom: 80px;
            overflow-x: hidden;
        }

        /* --- MAIN GLASS CONTAINER --- */
        .glass-container {
            max-width: 1200px;
            margin: 40px auto;
            padding: 20px;
            background: rgba(255, 255, 255, 0.1); /* Glassmorphism effect */
            backdrop-filter: blur(5px);
            -webkit-backdrop-filter: blur(5px);
            border-radius: 15px;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.2);
            width: 95%; 
            position: relative;
            z-index: 1; 
        }

        .page-title {
            text-align: center;
            margin-bottom: 30px;
            font-size: 2rem;
            font-weight: 600;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
            color: white;
        }

        /* --- EVENT CARD STYLES --- */
        .event-card {
            background: rgba(255, 255, 255, 0.08);
            backdrop-filter: blur(20px) saturate(200%);
            border-radius: 20px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            border: 1px solid rgba(255, 255, 255, 0.15);
            overflow: hidden;
            width: 100%;
            display: flex;
            flex-direction: column;
            background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.02) 100%);
            margin-bottom: 20px;
            transition: transform 0.3s ease;
        }

        .event-card:hover {
            transform: translateY(-5px);
        }

        .img-wrapper {
            position: relative;
            width: 100%;
            padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
            background: #000;
            overflow: hidden;
            border-top-left-radius: 20px;
            border-top-right-radius: 20px;
        }

        .img-wrapper img {
            position: absolute;
            top: 0; left: 0; width: 100%; height: 100%;
            object-fit: cover;
        }

        /* Yellow Title Box from Reference */
        .program-title-box {
            background-color: #FFC107; /* Play button yellow */
            color: #1A237E; /* Deep Blue text (matches theme contrast) */
            padding: 10px 25px;
            border-radius: 30px; /* Curved box */
            font-size: 1.1rem;
            font-family: 'Poppins', sans-serif;
            font-weight: 700;
            display: inline-block;
            box-shadow: 0 4px 10px rgba(0,0,0,0.3);
            text-decoration: none;
            line-height: 1.4;
          
        }

        .card-body {
            padding: 15px;
            text-align: left;
        }
    </style>
</head>
<body>

<?php include '../components/header.php'; // Header inclusion based on project structure ?>

<div class="glass-container">
    <h1 class="page-title">Our Special Events</h1>

    <div class="row g-4">
        <?php foreach ($events as $event): ?>
            <div class="col-md-6 col-lg-4">
                <a href="<?php echo htmlspecialchars($event['event_page_url']); ?>" class="text-decoration-none">
                    <div class="event-card">
                        <div class="img-wrapper">
                            <img src="/Uploads/events/<?php echo $event['thumbnail_url']; ?>" 
                                 alt="<?php echo htmlspecialchars($event['title']); ?>">
                        </div>
                        <div class="card-body">
                            <div class="program-title-box">
                                <?php echo htmlspecialchars($event['title']); ?>
                            </div>
                        </div>
                    </div>
                </a>
            </div>
        <?php endforeach; ?>
    </div>
</div>

<?php include '../components/footer.php'; // Footer inclusion based on project structure ?>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>