<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Gestion des Employés - 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">
    <style>
        .badge-status {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
        }
        .badge-status.active { background: #d4edda; color: #155724; }
        .badge-status.inactive { background: #f8d7da; color: #721c24; }
        .badge-status.blocked { background: #fff3cd; color: #856404; }
    </style>
</head>
<body>
<?php include "../../../../../layouts/admin/header.php" ?>
<?php include "../../../../../layouts/admin/personnel/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 Employés</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">Actifs</span>
                    <span class="stat-value" id="statActive">0</span>
                </div>
            </div>
            <div class="stat-card">
                <div class="stat-icon">🔒</div>
                <div class="stat-info">
                    <span class="stat-label">Bloqués</span>
                    <span class="stat-value" id="statBlocked">0</span>
                </div>
            </div>
        </div>

        <!-- Search Section -->
        <div class="search-section">
            <form id="searchForm" class="search-form">
                <div class="form-group">
                    <label for="searchNom">Nom</label>
                    <input type="text" id="searchNom" placeholder="Rechercher par nom...">
                </div>
                <div class="form-group">
                    <label for="searchPrenom">Prénom</label>
                    <input type="text" id="searchPrenom" placeholder="Rechercher par prénom...">
                </div>
                <div class="form-group">
                    <label for="searchCin">CIN</label>
                    <input type="text" id="searchCin" placeholder="Rechercher par CIN...">
                </div>
                <div class="form-group">
                    <label for="searchEmail">Email</label>
                    <input type="text" id="searchEmail" placeholder="Rechercher par email...">
                </div>
                <div class="form-group">
                    <label for="searchStatus">Statut</label>
                    <select id="searchStatus">
                        <option value="">Tous</option>
                        <option value="ACTIF">Actif</option>
                        <option value="INACTIF">Inactif</option>
                    </select>
                </div>
                <div class="search-actions">
                    <button type="submit" class="btn btn-primary">
                        <i class="fas fa-search"></i> Rechercher
                    </button>
                    <button type="reset" class="btn btn-secondary" onclick="resetSearch()">
                        <i class="fas fa-undo"></i> Réinitialiser
                    </button>
                    <button type="button" class="btn btn-success" onclick="openCreateModal()">
                        <i class="fas fa-plus"></i> Nouvel Employé
                    </button>
                    <button type="button" class="btn btn-info" onclick="exportEmployees()">
                        <i class="fas fa-file-export"></i> Exporter
                    </button>
                </div>
            </form>
        </div>

        <!-- Table -->
        <div class="table-container">
            <div class="table-wrapper">
                <table>
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>Code</th>
                        <th>Nom</th>
                        <th>Prénom</th>
                        <th>CIN</th>
                        <th>Email</th>
                        <th>Login</th>
                        <th>Grade</th>
                        <th>Statut</th>
                        <th>Actions</th>
                    </tr>
                    </thead>
                    <tbody id="tableBody">
                    <tr>
                        <td colspan="10" 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>