<?php
session_start();
$db_path = file_exists('includes/db.php') ? 'includes/db.php' : '../includes/db.php';
if (file_exists($db_path)) {
    require $db_path;
} else {
    $conn = new mysqli('localhost', 'root', '', 'bajipari');
}

// Auth Check
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit();
}

$user_id = $_SESSION['user_id'];

// --- Data Fetch Logic (Placeholder) ---
// বর্তমানে ডাটাবেসে স্পিন টেবিল নেই, তাই ফাঁকা অ্যারে রাখা হয়েছে যাতে "No Data" দেখায়
$running_spins = []; 
$completed_spins = [];

// যদি ভবিষ্যতে টেবিল থাকে, তখন এমন কোড হবে:
// $running_spins = $conn->query("SELECT * FROM player_spins WHERE user_id=$user_id AND status='active'");
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Free Spin</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">

    <style>
        body { 
            background-color: #121619; 
            color: #d1d5db; 
            font-family: 'Roboto', sans-serif; 
            padding-bottom: 80px;
        }

        /* --- Header --- */
        .header-bg { 
            background-color: #232a31; 
            padding: 15px; 
            display: flex; 
            justify-content: center; 
            align-items: center; 
            position: relative;
            border-bottom: 1px solid #2f3840;
        }
        .close-btn {
            position: absolute;
            right: 15px;
            font-size: 18px;
            color: #9ca3af;
        }

        /* --- Tabs --- */
        .tabs-container {
            display: flex;
            background-color: #232a31;
            border-bottom: 1px solid #2f3840;
        }
        .tab-btn {
            flex: 1;
            text-align: center;
            padding: 12px 0;
            font-size: 14px;
            font-weight: 500;
            color: #9ca3af;
            cursor: pointer;
            position: relative;
        }
        .tab-btn.active {
            color: #fff;
            font-weight: bold;
        }
        /* White Underline Indicator */
        .tab-btn.active::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 2px;
            background-color: #fff;
        }

        /* --- No Data State --- */
        .no-data {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 400px; /* Center vertically in view */
            opacity: 0.3;
        }
        .clipboard-icon {
            width: 60px;
            margin-bottom: 15px;
            filter: invert(1); /* Make black icon white */
        }

        /* Content Logic */
        .tab-content { display: none; }
        .tab-content.active { display: block; }

        /* Bottom Nav */
        .bottom-nav { background-color: #000; border-top: 1px solid #222; }
        .nav-item { color: #6b7280; } .nav-item.active { color: #facc15; }
    </style>
</head>
<body>

    <div class="header-bg">
        <h1 class="text-white font-medium text-base">Free Spin</h1>
        <a href="account.php" class="close-btn"><i class="fas fa-times"></i></a>
    </div>

    <div class="tabs-container">
        <div class="tab-btn active" onclick="switchTab('running', this)">Running</div>
        <div class="tab-btn" onclick="switchTab('completed', this)">Completed</div>
    </div>

    <div id="running" class="tab-content active">
        <?php if (!empty($running_spins)): ?>
            <?php else: ?>
            <div class="no-data">
                <img src="https://cdn-icons-png.flaticon.com/512/7486/7486747.png" class="clipboard-icon">
                <p class="text-xs text-gray-400 font-medium">No Data</p>
            </div>
        <?php endif; ?>
    </div>

    <div id="completed" class="tab-content">
        <?php if (!empty($completed_spins)): ?>
            <?php else: ?>
            <div class="no-data">
                <img src="https://cdn-icons-png.flaticon.com/512/7486/7486747.png" class="clipboard-icon">
                <p class="text-xs text-gray-400 font-medium">No Data</p>
            </div>
        <?php endif; ?>
    </div>

    <div class="fixed bottom-0 left-0 w-full h-[60px] bottom-nav z-50 flex justify-between items-center px-6">
        <a href="index.php" class="flex flex-col items-center justify-center nav-item">
            <i class="fas fa-home text-lg mb-1"></i>
            <span class="text-[10px]">Home</span>
        </a>
        <a href="promotions.php" class="flex flex-col items-center justify-center nav-item">
            <i class="fas fa-gift text-lg mb-1"></i>
            <span class="text-[10px]">Promotions</span>
        </a>
        <a href="deposit.php" class="flex flex-col items-center justify-center nav-item">
            <i class="fas fa-wallet text-lg mb-1"></i>
            <span class="text-[10px]">Deposit</span>
        </a>
        <a href="account.php" class="flex flex-col items-center justify-center nav-item active">
            <i class="fas fa-user text-lg mb-1"></i>
            <span class="text-[10px]">My Account</span>
        </a>
    </div>

    <script>
        function switchTab(tabId, btn) {
            // Hide all tabs
            document.querySelectorAll('.tab-content').forEach(el => el.classList.remove('active'));
            // Remove active style from buttons
            document.querySelectorAll('.tab-btn').forEach(el => el.classList.remove('active'));
            
            // Show target
            document.getElementById(tabId).classList.add('active');
            btn.classList.add('active');
        }
    </script>

</body>
</html>