<?php
// Démarrer la session pour récupérer l'ID de l'étudiant connecté
session_start();

// Récupérer l'ID de l'étudiant depuis la session (à adapter selon votre système)
$student_id = $_SESSION['student_id']; // Par défaut 2 pour le test

// Get student data from sessionStorage via JavaScript or from PHP session
// For PHP, you might want to store student data in session as well
if (isset($_SESSION['student'])) {
    $student_data = $_SESSION['student'];
    $student_id = $student_data["id"];
} else {
    // Fallback - will be populated by JavaScript from sessionStorage
    $student_data = null;
    header('Location: /est-concours/app/cnx/student/login');
    exit(); // Always call exit() after header redirect

}

// Récupérer le message de notification si présent
$notification = isset($_GET['notification']) ? $_GET['notification'] : '';
$notification_type = isset($_GET['notification_type']) ? $_GET['notification_type'] : '';
?>
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mes Inscriptions - Liste</title>
    <!-- Bootstrap CSS -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <!-- Google Fonts - Montserrat -->
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap"
          rel="stylesheet">
    <link href="../../../../css/student-styles.css" rel="stylesheet">

</head>
<body>

<?php include "../../../../layouts/student/header.php"; ?>

<!-- Spinner Overlay -->
<div class="spinner-overlay" id="spinnerOverlay">
    <div class="spinner-box">
        <div class="spinner-border text-success" role="status">
            <span class="visually-hidden">Chargement...</span>
        </div>
        <p class="mt-3 mb-0 text-muted">Chargement de vos inscriptions...</p>
    </div>
</div>


<!-- Notification Container -->
<div class="notification-container" id="notificationContainer">
    <?php if ($notification): ?>
        <div class="notification <?php echo $notification_type ?: 'info'; ?>" id="notificationMessage">
        <span class="notification-icon">
            <i class="fas <?php echo $notification_type === 'success' ? 'fa-check-circle' : ($notification_type === 'error' ? 'fa-exclamation-circle' : 'fa-info-circle'); ?>"></i>
        </span>
            <span class="notification-message"><?php echo htmlspecialchars($notification); ?></span>
            <button class="notification-close" onclick="closeNotification(this)"><i class="fas fa-times"></i></button>
        </div>
    <?php endif; ?>
</div>

<main class="main-content">
    <div class="container-custom">
        <!-- Page Header -->
        <div class="page-header">
            <div class="row align-items-center">
                <div class="col-md-8">
                    <h1><i class="fas fa-file-alt text-success me-2"></i>Mes Inscriptions</h1>
                    <p>Consultez et gérez toutes vos inscriptions aux concours</p>
                </div>
                <div class="col-md-4 text-md-end">
                    <a href="../create/index.php" class="btn btn-custom-primary">
                        <i class="fas fa-plus me-2"></i>Nouvelle Inscription
                    </a>
                </div>


                <div class="col-md-4 text-md-end">
                    <input type="text" class="form-control" id="student_id" name="student_id"
                           placeholder="Ex: AB123456" maxlength="8" hidden="hidden" required
                           value="<?php echo $student_id ?>">
                    <div class="error-message" id="cin-error">Le CIN doit contenir 8
                        caractères.
                    </div>
                </div>
            </div>
        </div>

        <!-- Tab Navigation -->
        <div class="tab-navigation">
            <button class="tab-btn active" data-tab="mes-inscriptions" onclick="switchTab('mes-inscriptions')">
                <i class="fas fa-list me-2"></i>Mes Inscriptions
                <span class="tab-badge" id="totalCount">0</span>
            </button>
        </div>

        <!-- Tab Content: Mes Inscriptions -->
        <div class="tab-content active" id="tab-mes-inscriptions">
            <div id="inscriptionsContainer">
                <!-- Les cartes d'inscriptions seront chargées ici dynamiquement -->
            </div>
        </div>

        <!-- Tab Content: Concours Disponibles -->
        <div class="tab-content" id="tab-concours-disponibles">
            <div id="concoursContainer">
                <!-- Les cartes de concours disponibles seront chargées ici dynamiquement -->
            </div>
        </div>
    </div>
</main>

<?php include "../../../../layouts/student/footer.php"; ?>

<!-- Bootstrap JS Bundle -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>

<!-- Votre JavaScript personnalisé -->
<script src="main.js"></script>


</body>
</html>
