<?php
session_start();
$candidat = $_SESSION['candidat'];
if (!isset($candidat) || !isset($candidat['id'])) {
    header('Location: /est-concours/app/cnx/candidat/login/');
    exit();
}
$candidat_id = $candidat['id'];
?>
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mon Profil - EST Concours</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link href="/est-concours/app/css/candidat-styles.css" rel="stylesheet">
    <style>
        .profile-card {
            max-width: 650px;
            margin: 40px auto;
            background: #fff;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.08);
            overflow: hidden;
        }
        .profile-header {
            background: linear-gradient(135deg, #00c0ed, #0098c9);
            padding: 30px;
            text-align: center;
            color: white;
        }
        .profile-header i { font-size: 60px; margin-bottom: 10px; }
        .profile-header h4 { margin: 0; font-weight: 700; }
        .nav-tabs .nav-link { color: #6c757d; font-weight: 500; }
        .nav-tabs .nav-link.active { color: #00c0ed; border-bottom: 2px solid #00c0ed; font-weight: 600; }
        .btn-save {
            background-color: #b7d22b;
            color: white;
            border: none;
            padding: 10px 30px;
            border-radius: 6px;
            font-weight: 600;
            width: 100%;
        }
        .btn-save:hover { background-color: #00c0ed; color: white; }
    </style>
</head>
<body>

<?php include __DIR__ . "/../../../layouts/candidat/header.php"; ?>

<!-- Candidat ID hidden -->
<input type="hidden" id="candidat_id" value="<?= $candidat_id ?>">

<div class="container">
    <div class="profile-card">

        <!-- Header -->
        <div class="profile-header">
            <i class="fas fa-user-circle"></i>
            <h4 id="full-name">Chargement...</h4>
            <small id="candidat-email"></small>
        </div>

        <!-- Alert messages -->
        <div id="alert-box" class="mx-4 mt-3" style="display:none;"></div>

        <!-- Tabs -->
        <div class="px-4 pt-3">
            <ul class="nav nav-tabs">
                <li class="nav-item">
                    <a class="nav-link active" href="#" onclick="showTab('profile', event)">
                        <i class="fas fa-user"></i> Mon Profil
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#" onclick="showTab('password', event)">
                        <i class="fas fa-lock"></i> Mot de passe
                    </a>
                </li>
            </ul>
        </div>

        <!-- Tab: Modifier Profil -->
        <div id="tab-profile" class="p-4">
            <div class="mb-3">
                <label class="form-label fw-semibold">Nom</label>
                <input type="text" id="nom" class="form-control" required>
            </div>
            <div class="mb-3">
                <label class="form-label fw-semibold">Prénom</label>
                <input type="text" id="prenom" class="form-control" required>
            </div>
            <div class="mb-3">
                <label class="form-label fw-semibold">Email</label>
                <input type="email" id="email" class="form-control" required>
            </div>
            <div class="mb-3">
                <label class="form-label fw-semibold">CIN</label>
                <input type="text" id="cin" class="form-control" placeholder="Ex: AB123456" maxlength="10">
                <small class="text-muted">Laissez vide si vous ne souhaitez pas modifier</small>
            </div>
            <div class="mb-4">
                <label class="form-label fw-semibold">Numéro de téléphone</label>
                <input type="text" id="phone" class="form-control">
            </div>
            <button class="btn btn-save" onclick="updateProfile()">
                <i class="fas fa-save"></i> Enregistrer
            </button>
        </div>

        <!-- Tab: Modifier Mot de passe -->
        <div id="tab-password" class="p-4" style="display:none;">
            <div class="mb-3">
                <label class="form-label fw-semibold">Nouveau mot de passe</label>
                <input type="password" id="new_password" class="form-control" placeholder="Minimum 6 caractères">
            </div>
            <div class="mb-4">
                <label class="form-label fw-semibold">Confirmer le mot de passe</label>
                <input type="password" id="confirm_password" class="form-control" placeholder="Répétez le mot de passe">
            </div>
            <button class="btn btn-save" onclick="updatePassword()">
                <i class="fas fa-key"></i> Modifier le mot de passe
            </button>
        </div>

    </div>
</div>

<?php include __DIR__ . "/../../../layouts/candidat/footer.php"; ?>

<script src="main.js"></script>
</body>
</html>