<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Gestion des Demandes de Documents - EST</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <link rel="stylesheet" href="../../../../css/admin-styles.css">
</head>
<body>
<?php include "../../../../layouts/admin/header.php" ?>
<?php include "../../../../layouts/admin/espace-prof/nav-second-level.php" ?>

<main class="main-content">
    <div class="container">

        <!-- Stats Cards -->
        <div class="stats-grid" id="statsGrid">
            <div class="stat-card">
                <div class="stat-icon">📄</div>
                <div class="stat-info">
                    <span class="stat-label">Total Demandes</span>
                    <span class="stat-value" id="statTotal">0</span>
                </div>
            </div>
            <div class="stat-card">
                <div class="stat-icon">⏳</div>
                <div class="stat-info">
                    <span class="stat-label">En Attente</span>
                    <span class="stat-value" id="statEnAttente">0</span>
                </div>
            </div>
            <div class="stat-card">
                <div class="stat-icon">✅</div>
                <div class="stat-info">
                    <span class="stat-label">Approuvées</span>
                    <span class="stat-value" id="statApprouvees">0</span>
                </div>
            </div>
            <div class="stat-card">
                <div class="stat-icon">❌</div>
                <div class="stat-info">
                    <span class="stat-label">Rejetées</span>
                    <span class="stat-value" id="statRejetees">0</span>
                </div>
            </div>
        </div>

        <!-- Search Section -->
       <div class="search-section">
    <form id="searchForm">

        <div style="display:grid; grid-template-columns:repeat(4, 1fr); gap:15px; align-items:end;">

            <div class="form-group">
                <label for="searchId">ID</label>
                <input type="text" id="searchId" placeholder="Rechercher par ID...">
            </div>

            <div class="form-group">
                <label for="searchLibelle">Libellé</label>
                <input type="text" id="searchLibelle" placeholder="Rechercher par libellé...">
            </div>

            <div class="form-group">
                <label for="searchProfesseur">Professeur</label>
                <select id="searchProfesseur">
                    <option value="">Tous les professeurs</option>
                </select>
            </div>

            <div class="form-group">
                <label for="searchTypeDocument">Type de Document</label>
                <select id="searchTypeDocument">
                    <option value="">Tous les types</option>
                </select>
            </div>

            <div class="form-group">
                <label for="searchEtat">État</label>
                <select id="searchEtat">
                    <option value="">Tous les états</option>
                </select>
            </div>

            <div class="form-group">
                <label for="searchDateDebut">Date Soumission (Début)</label>
                <input type="date" id="searchDateDebut">
            </div>

            <div class="form-group">
                <label for="searchDateFin">Date Soumission (Fin)</label>
                <input type="date" id="searchDateFin">
            </div>

        </div>

        <div style="display:flex; gap:10px; flex-wrap:wrap; margin-top:15px;">
            <button type="submit" class="btn btn-primary">
                <i class="fas fa-search"></i>
            </button>
            <button type="reset" class="btn btn-secondary" onclick="resetSearch()">
                <i class="fas fa-undo"></i>
            </button>
            <button type="button" class="btn btn-success" onclick="openCreateModal()">
                <i class="fas fa-plus"></i>
            </button>
            <button type="button" class="btn btn-info" onclick="exportDemandes()">
                <i class="fas fa-file-export"></i>
            </button>
        </div>

    </form>
</div>
        <!-- Table -->
        <div class="table-container">
            <div class="table-wrapper">
                <table>
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>Libellé</th>
                        <th>Professeur</th>
                        <th>Type de Document</th>
                        <th>État</th>
                        <th>Date Soumission</th>
                        <th>Date Réponse</th>
                        <th>Actions</th>
                    </tr>
                    </thead>
                    <tbody id="tableBody">
                    <tr>
                        <td colspan="8" style="text-align: center; padding: 40px;">
                            <div class="loading active">
                                <div class="spinner"></div>
                                <p style="margin-top: 10px;">Chargement des données...</p>
                            </div>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div class="pagination">
                <div class="pagination-info" id="paginationInfo">Affichage de 0 à 0 sur 0</div>
                <div class="pagination-buttons" id="paginationButtons">
                    <button onclick="changePage('prev')" id="prevBtn">◀ Précédent</button>
                    <span id="pageNumbers"></span>
                    <button onclick="changePage('next')" id="nextBtn">Suivant ▶</button>
                </div>
            </div>
        </div>
    </div>
</main>

<?php include "../../../../layouts/admin/footer.php" ?>

<!-- Modals -->
<?php include "../create-edit/modal.php" ?>
<?php include "../view/modal.php" ?>

<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js"></script>
<script src="main.js"></script>
</body>
</html>
