<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>🐉 DragonBank - {% block title %}Accueil{% endblock %}</title>
    
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.2/font/bootstrap-icons.css" rel="stylesheet">
    <!-- Custom CSS -->
    <link href="{{ url_for('static', filename='style.css') }}" rel="stylesheet">
</head>
<body>
    {% if session.get('token') %}
    <!-- NAVBAR CONNECTÉ -->
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="{{ url_for('dashboard') }}">
                <span class="dragon-icon">🐉</span> DragonBank
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint == 'dashboard' %}active{% endif %}" 
                           href="{{ url_for('dashboard') }}">
                            <i class="bi bi-speedometer2"></i> Tableau de bord
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint in ['accounts', 'open_account'] %}active{% endif %}" 
                           href="{{ url_for('accounts') }}">
                            <i class="bi bi-wallet2"></i> Mes comptes
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint in ['beneficiaries', 'add_beneficiary'] %}active{% endif %}" 
                           href="{{ url_for('beneficiaries') }}">
                            <i class="bi bi-people"></i> Bénéficiaires
                        </a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle {% if request.endpoint in ['transfer', 'transfer_external'] %}active{% endif %}" 
                           href="#" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-arrow-left-right"></i> Virements
                        </a>
                        <ul class="dropdown-menu">
                            <li><a class="dropdown-item" href="{{ url_for('transfer') }}">
                                <i class="bi bi-arrow-repeat"></i> Virement interne / Personne
                            </a></li>
                            <li><a class="dropdown-item" href="{{ url_for('transfer_external') }}">
                                <i class="bi bi-bank"></i> Virement externe
                            </a></li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.endpoint == 'transactions' %}active{% endif %}" 
                           href="{{ url_for('transactions') }}">
                            <i class="bi bi-clock-history"></i> Historique
                        </a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item me-3 d-flex align-items-center">
                        <span class="user-badge">
                            <i class="bi bi-person-circle"></i> 
                            {{ session.get('user', {}).get('first_name', '') }} 
                            {{ session.get('user', {}).get('last_name', '') }}
                        </span>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-danger" href="{{ url_for('logout') }}">
                            <i class="bi bi-box-arrow-right"></i> Déconnexion
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    {% endif %}

    <!-- FLASH MESSAGES -->
    <div class="container-fluid mt-3">
        {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            {% for category, message in messages %}
            <div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
                {% if category == 'success' %}
                    <i class="bi bi-check-circle-fill"></i>
                {% elif category == 'danger' %}
                    <i class="bi bi-exclamation-triangle-fill"></i>
                {% elif category == 'warning' %}
                    <i class="bi bi-exclamation-circle-fill"></i>
                {% else %}
                    <i class="bi bi-info-circle-fill"></i>
                {% endif %}
                {{ message }}
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
            {% endfor %}
        {% endif %}
        {% endwith %}
    </div>

    <!-- CONTENU PRINCIPAL -->
    {% block content %}{% endblock %}

    {% if session.get('token') %}
    <footer class="footer">
        <p>🐉 <strong>DragonBank</strong> &copy; 2024 — Votre banque de confiance | 
           Sécurisé par <a href="#">Dragon Shield™</a></p>
    </footer>
    {% endif %}

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
    {% block scripts %}{% endblock %}
</body>
</html>