<!DOCTYPE html>
<html th:fragment="layout (title, csspage, content)" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>[[${title}]]</title>
    <link rel="icon" th:href="@{/img/favicon.ico}" />
    <link href="/css/bootstrap/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/assets/fontawesome/css/all.css">
    <link rel="stylesheet" href="/css/style.css">
    <style>
        /* Ajoutez une classe pour le footer non sticky */
        .non-sticky-footer {
            position: static !important; /* Annule la position sticky */
            bottom: 0; /* Le place en bas de la page */
            width: 100%; /* Prend toute la largeur */
            background-color: #2a2b30;
        }
    </style>
</head>
<body>
    <header>
        <nav class="navbar navbar-expand-lg navbar navbar-dark bg-dark navbar-">
            <a class="navbar-brand" href="/enchere">
                <img href="/enchere" src="/img/logo.png" width="70" height="70" alt="Logo">
                <label href="/enchere" class="text-light"><strong>ENI-Encheres</strong></label>
            </a>
            <div th:if="${#authentication.principal != 'anonymousUser'}" class="text-light text-center d-flex justify-content-center align-items-center">
                <span th:text="#{home.credit} + ${user.getCredit()} + '  '"></span>
                <i class="fas fa-coins ml-1"></i>
                <span th:text="#{home.credit.enchere} + ${enchereUser}" class="ml-4"></span>
                <i class="fas fa-coins ml-1"></i>
            </div>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div  class="collapse navbar-collapse " id="navbarNav">
                <ul class="navbar-nav ml-auto">
                    <li class="nav-item" th:if="${#authentication.principal != 'anonymousUser'}" th:classappend="${requestURI == '/enchere'} ? 'active'">
                        <a class="nav-link" href="/enchere" th:text="#{home.nav.enchere}"> <span class="sr-only" >(current)</span></a>
                    </li>
                    <li class="nav-item" th:if="${#authentication.principal != 'anonymousUser'}" th:classappend="${requestURI == '/article/new'} ? 'active'">
                        <a class="nav-link" href="/article/new" th:text="#{home.nav.vend}"></a>
                    </li>
                    <li  class="nav-item" th:if="${#authentication.principal == 'anonymousUser'}">
                        <a class="btn btn-primary" href="/login" role="button" style="background-color: #1B4463;" th:text="#{home.nav.login}"></a>
                    </li>
                    <li class="nav-item dropdown" th:if="${#authentication.principal != 'anonymousUser'}">
                        <a class="nav-link dropdown-toggle"  id="navbarDropdownMenuLink" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            <i class="fas fa-user"></i> <!-- Icône de profil -->
                        </a>
                        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
                            <a class="dropdown-item" href="/profil" th:text="#{home.profil.profil}"></a> <!-- Bouton de profil -->
                            <a class="dropdown-item" href="/bank" th:text="#{home.profil.bank}"></a>
                            <a class="dropdown-item" th:if="${#authorization.expression('hasRole(''ADMIN'')')}" href="/admin"> Administration </a>
                            <a class="dropdown-item" href="/logout" th:text="#{home.profil.logout}"></a> <!-- Bouton de déconnexion -->
                            <div class="dropdown-divider"></div> <!-- Diviseur -->
                            <a class="dropdown-item" th:href="@{/change-language}" th:text="#{home.button.lang}"></a> <!-- Option de changement de langue vers l'anglais --><!-- Option de changement de langue vers le français -->
                        </div>
                    </li>
                    <li class="nav-item" th:if="${#authentication.principal == 'anonymousUser'}">
                        <strong><a class="nav-link" href="#" th:href="@{/change-language}" th:text="#{home.button.lang2}"></a></strong>
                    </li>
                </ul>
            </div>
        </nav>

    </header>
    <div th:insert="${content}"></div>


    <footer class="fixed-bottom text-center text-lg-start bg-body-tertiary text-muted py-3 non-sticky-footer" style="background-color: #2a2b30;">
        <section class="py-4 mb-0" style="background-color: #2a2b30;">
            <div class="container text-lg-left text-md-start mt-4 mb-5">
                <div class="row">
                    <div class="col-md-3 col-lg-4 col-xl-3 mx-auto mb-4">
                        <h6 class="text-uppercase fw-bold mb-4">
                            <i class="fas fa-gem me-3"></i>ENI-Encheres
                        </h6>
                        <p th:text="#{footer.desc}">
                        </p>
                    </div>

                    <div class="col-md-2 col-lg-2 col-xl-2 mx-auto mb-4">
                        <h6 class="text-uppercase fw-bold mb-4">
                            Menu
                        </h6>
                        <p>
                            <a href="/enchere" class="text-reset" th:text="#{home.nav.enchere}"></a>
                        </p>
                        <p>
                            <a href="/article/new" class="text-reset" th:text="#{home.nav.vend}"></a>
                        </p>
                        <p>
                            <a href="/profil" class="text-reset" th:text="#{profil.title}"></a>
                        </p>
                    </div>

                    <div class="col-md-4 col-lg-3 col-xl-3 mx-auto mb-md-0 mb-4">
                        <h6 class="text-uppercase fw-bold mb-4">Contact</h6>
                        <p><i class="fas fa-home me-3"></i> 2a Rue Benjamin Franklin, 44800 Saint-Herblain</p>
                        <p>
                            <i class="fas fa-envelope me-3"></i>
                            editions@eni.fr
                        </p>
                        <p><i class="fas fa-phone me-3"></i> + 02 51 80 15 15</p>
                    </div>
                </div>
            </div>
        </section>

        <div class="text-center py-2 mt-0" style="background-color: #2a2b30;">
            © 2024 Copyright:
        </div>
    </footer>



    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script th:src="@{/js/toggleCheckbox.js}"></script>

    <script>
        // Script pour ajuster le footer en fonction de la hauteur du contenu
        $(document).ready(function() {
            adjustFooterPosition();

            $(window).on('resize', function() {
                adjustFooterPosition();
            });

            function adjustFooterPosition() {
                var windowHeight = $(window).height();
                var bodyHeight = $('body').height();

                if (windowHeight >= bodyHeight) {
                    // Si la fenêtre est plus grande que le contenu, le footer reste sticky
                    $('.non-sticky-footer').removeClass('non-sticky-footer');
                } else {
                    // Si le contenu dépasse la fenêtre, le footer n'est plus sticky
                    $('footer').addClass('non-sticky-footer');
                }
            }
        });
    </script>
</body>
</html>