<?php
include 'header.php';
if (!isset($_SESSION["USER_LOGIN"])){
      echo '<script>window.location.href = "login.php";</script>';
}
  
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Initialize variables
$msg = "";
$err = "";
$bookings = [];
$total_bookings = 0;


// Fetch total bookings (type = 'Fan Card Purchase')
if (empty($err)) {
    $query = "SELECT COUNT(*) as total
              FROM payments
              WHERE userid = $user_id AND type = 'Fan Card Purchase'";
    $result = mysqli_query($link, $query);
    if ($result) {
        $stats = mysqli_fetch_assoc($result);
        $total_bookings = $stats['total'];
    } else {
        $err = "Failed to fetch booking stats: " . mysqli_error($link);
    }
}

// Fetch individual bookings
if (empty($err)) {
    $query = "SELECT p.id, p.amount, p.status, p.event_name, p.meetup_date, p.meetup_time, 
                     p.event_time, p.event_date, p.duration_hours, p.location, p.special_requests, 
                     p.type, p.created_at,
                     c.name as name, c.image as image, c.category as celebrity_category
              FROM payments p
              LEFT JOIN celebrities c ON p.celebrity_id = c.id
              WHERE p.userid = $user_id AND p.type = 'Fan Card Purchase'
              ORDER BY p.created_at DESC";
              
    $result = mysqli_query($link, $query);
    if ($result) {
        while ($row = mysqli_fetch_assoc($result)) {
            $bookings[] = $row;
        }
    } else {
        $err = "Failed to fetch bookings: " . mysqli_error($link);
    }
}


?>


    <main class="flex-grow-1" style="padding-top: 80px;">
        
        
        <style>
    .page-header {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        color: white;
        padding: 3rem 0;
        border-radius: 0 0 30px 30px;
        margin-bottom: 2rem;
        position: relative;
        overflow: hidden;
    }

    .page-header::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: url('data:image/svg+xml,<svg width="60" height="60" viewBox="0 0 60 60" xmlns="http://www.w3.org/2000/svg"><g fill="none" fill-rule="evenodd"><g fill="%23ffffff" fill-opacity="0.1"><circle cx="12" cy="12" r="2"/><circle cx="48" cy="12" r="2"/><circle cx="12" cy="48" r="2"/><circle cx="48" cy="48" r="2"/></g></g></svg>');
    }

    .page-content {
        position: relative;
        z-index: 2;
    }

    .fan-card {
        border-radius: 20px;
        padding: 0;
        height: 350px;
        position: relative;
        overflow: hidden;
        transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        cursor: pointer;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        border: none;
    }

    .fan-card-inner {
        height: 100%;
        position: relative;
        overflow: hidden;
        border-radius: 20px;
        padding: 2rem;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .fan-card::before {
        content: '';
        position: absolute;
        top: -50%;
        right: -50%;
        width: 200%;
        height: 200%;
        background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
        transform: rotate(45deg);
        transition: all 0.6s ease;
        opacity: 0;
    }

    .fan-card:hover {
        transform: translateY(-15px) scale(1.03);
        box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
    }

    .fan-card:hover::before {
        top: -60%;
        right: -60%;
        opacity: 1;
    }

    .fan-card-gradient {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: linear-gradient(135deg, var(--card-bg-start) 0%, var(--card-bg-end) 100%);
        opacity: 0.95;
    }

    .fan-card-pattern {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: 
            radial-gradient(circle at 20% 80%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
            radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
            radial-gradient(circle at 40% 40%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
    }

    .fan-card-header {
        position: relative;
        z-index: 3;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 1.5rem;
    }

    .fan-card-type {
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 12px;
        padding: 0.5rem 1rem;
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 1px;
        text-transform: uppercase;
    }

    .fan-card-icon {
        width: 50px;
        height: 50px;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        transition: all 0.3s ease;
    }

    .fan-card:hover .fan-card-icon {
        transform: scale(1.1) rotate(5deg);
        background: rgba(255, 255, 255, 0.3);
    }

    .fan-card-content {
        position: relative;
        z-index: 3;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .celebrity-name {
        font-size: 1.5rem;
        font-weight: 700;
        margin-bottom: 0.5rem;
        text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .celebrity-profession {
        font-size: 0.9rem;
        opacity: 0.8;
        margin-bottom: 1.5rem;
        font-weight: 500;
    }

    .card-holder-info {
        background: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 12px;
        padding: 1rem;
        margin-bottom: 1.5rem;
    }

    .card-holder-name {
        font-size: 1rem;
        font-weight: 600;
        margin-bottom: 0.25rem;
    }

    .card-number {
        font-size: 0.8rem;
        opacity: 0.7;
        font-family: 'Courier New', monospace;
        letter-spacing: 1px;
    }

    .fan-card-footer {
        position: relative;
        z-index: 3;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .expiry-info {
        display: flex;
        flex-direction: column;
    }

    .expiry-label {
        font-size: 0.7rem;
        opacity: 0.7;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 0.25rem;
    }

    .expiry-date {
        font-size: 1rem;
        font-weight: 600;
        font-family: 'Courier New', monospace;
    }

    .status-badge {
        padding: 0.5rem 1rem;
        border-radius: 20px;
        font-size: 0.8rem;
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 0.5rem;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.3);
    }

    .status-active {
        background: rgba(34, 197, 94, 0.2);
        color: #16a34a;
        border-color: rgba(34, 197, 94, 0.3);
    }

    .status-inactive {
        background: rgba(239, 68, 68, 0.2);
        color: #dc2626;
        border-color: rgba(239, 68, 68, 0.3);
    }

    .empty-state {
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 20px;
        padding: 4rem 2rem;
        text-align: center;
        margin: 2rem 0;
    }

    .empty-state-icon {
        width: 100px;
        height: 100px;
        border-radius: 50%;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 2rem;
        font-size: 2.5rem;
        color: white;
    }

    .back-btn {
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 12px;
        padding: 0.75rem 1.5rem;
        color: white;
        text-decoration: none;
        transition: all 0.3s ease;
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
    }

    .back-btn:hover {
        background: rgba(255, 255, 255, 0.3);
        color: white;
        transform: translateX(-5px);
        text-decoration: none;
    }

    .stats-badge {
        background: rgba(255, 255, 255, 0.2);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: 50px;
        padding: 0.5rem 1rem;
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        margin-left: 1rem;
    }

    /* Card shimmer effect */
    .fan-card::after {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
        transition: left 0.5s;
    }

    .fan-card:hover::after {
        left: 100%;
    }

    @media (max-width: 768px) {
        .page-header {
            padding: 2rem 0;
        }
        
        .fan-card {
            height: 320px;
        }
        
        .fan-card-inner {
            padding: 1.5rem;
        }
        
        .celebrity-name {
            font-size: 1.3rem;
        }
        
        .empty-state {
            padding: 3rem 1.5rem;
        }
        
        .empty-state-icon {
            width: 80px;
            height: 80px;
            font-size: 2rem;
        }

        .stats-badge {
            margin-left: 0;
            margin-top: 1rem;
        }
    }
</style>

<div class="container-fluid px-0">
    <!-- Page Header -->
    <div class="page-header">
        <div class="container">
            <div class="page-content">
                <div class="d-flex justify-content-between align-items-center flex-wrap">
                    <div>
                        <h1 class="display-5 fw-bold mb-3">
                            <i class="fas fa-id-card me-3"></i>
                            My Fan Cards
                        </h1>
                        <p class="fs-6 opacity-90 mb-0">Your exclusive collection of celebrity fan cards</p>
                    </div>
                    <div class="d-flex align-items-center flex-wrap">
                        <a href="dashboard.php" class="back-btn">
                            <i class="fas fa-arrow-left"></i>
                            Back to Dashboard
                        </a>
                        <div class="stats-badge">
                            <i class="fas fa-collection"></i>
                            <span><?php echo $total_bookings ?> Cards</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

        <div class="container py-4">
            <div class="row g-4">
                
                <?php foreach ($bookings as $booking): ?>
                <div class="col-lg-4 col-md-6">
                    <div class="fan-card" 
                         style="--card-bg-start: #ff9800; 
                                --card-bg-end: #ff9800dd;">
                        <div class="fan-card-gradient"></div>
                        <div class="fan-card-pattern"></div>
                        
                        <div class="fan-card-inner" style="color: #000000;">
                            <!-- Header -->
                            <div class="fan-card-header">
                                <?php if($booking['type'] == 1){ ?>
                                <div class="fan-card-type">
                                    Regular Fan Card
                                </div>
                                <?php }elseif($booking['type'] == 2){ ?>
                                <div class="fan-card-type">
                                    VVIP Fan Card
                                </div>
                                <?php }elseif($booking['type'] == 3){ ?>
                                <div class="fan-card-type">
                                    Gold
                                </div>
                                <?php }else{ ?>
                                <div class="fan-card-type">
                                    VIP Royal Card
                                </div>
                                <?php } ?>
                                
                                
                                
                                
                                <div class="fan-card-icon">
                                    <i class="fas fa-id-card"></i>
                                </div>
                            </div>
                            
                            <!-- Content -->
                            <div class="fan-card-content">
                                <div class="celebrity-name"><?php echo $booking['name']; ?></div>
                                <div class="celebrity-profession"><?php echo $booking['celebrity_category']; ?></div>
                                
                                <div class="card-holder-info">
                                    <div class="card-holder-name"><?php echo $name ?></div>
                                    <div class="card-number">Card #FC128555853</div>
                                </div>
                            </div>
                            
                            <!-- Footer -->
                            <div class="fan-card-footer">
                                <div class="expiry-info">
                                    <div class="expiry-label">Valid Until</div>
                                    <div class="expiry-date">07/26</div>
                                </div>
                                <?php if($booking['status'] == "Pending" ){ ?>
                                <div class="status-badge status-inactive">
                                    <i class="fas fa-times-circle"></i>
                                    Pending
                                </div>
                                <?php }else{ ?>
                                 <div class="status-badge status-completed">
                                    <i class="fas fa-check-circle"></i>
                                    Completed
                                </div>

                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
                <?php endforeach; ?>
                
                
              
                    </div>
    </div>

<script>
    // Enhanced card interactions
    document.querySelectorAll('.fan-card').forEach(card => {
        card.addEventListener('click', function(e) {
            // Add ripple effect
            const ripple = document.createElement('div');
            const rect = this.getBoundingClientRect();
            const size = Math.max(rect.width, rect.height);
            const x = e.clientX - rect.left - size / 2;
            const y = e.clientY - rect.top - size / 2;
            
            ripple.style.cssText = `
                position: absolute;
                width: ${size}px;
                height: ${size}px;
                left: ${x}px;
                top: ${y}px;
                background: rgba(255, 255, 255, 0.3);
                border-radius: 50%;
                transform: scale(0);
                animation: ripple 0.6s linear;
                pointer-events: none;
                z-index: 1000;
            `;
            
            this.appendChild(ripple);
            
            setTimeout(() => {
                ripple.remove();
            }, 600);
        });
        
        // Add hover sound effect trigger
        card.addEventListener('mouseenter', function() {
            this.style.transform = 'translateY(-15px) scale(1.03)';
        });
        
        card.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(0) scale(1)';
        });
    });
    
    // Add CSS for ripple animation
    const style = document.createElement('style');
    style.textContent = `
        @keyframes ripple {
            to {
                transform: scale(2);
                opacity: 0;
            }
        }
    `;
    document.head.appendChild(style);
</script>
    </main>

  <?php
include 'footer.php';

?>
