@using System.Security.Claims

<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - Chat</title>

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
    <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
    <link rel="stylesheet" href="~/css/layout.css" asp-append-version="true" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
    
    <style>
        #wrapper {
            opacity: 1;
            transition: opacity 0.3s ease-in-out;
            display: block;
        }

        #wrapper.fade-out {
            opacity: 0;
        }

        .loading {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(255, 255, 255, 0.8);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 9999;
        }

        .loading .spinner {
            width: 40px;
            height: 40px;
            border: 4px solid #f3f3f3;
            border-top: 4px solid #3498db;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @@keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        body {
            display: block;
        }
    </style>
    
    @await RenderSectionAsync("Styles", required: false)
</head>
<body>
    <partial name="_Busy" />
    <div id="wrapper">
        <nav id="nav-bar" class="navbar navbar-expand-lg navbar-dark">
            <!-- Seu código de navegação existente -->
            <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Chat IA</a>
            <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="navbar-collapse collapse" id="navbarNav">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
                    </li>
                    @if (User!=null && User.Identity!=null && User.Identity.IsAuthenticated)
                    {
                        <li class="nav-item">
                            <a class="nav-link text-white" asp-area="" asp-controller="Chat" asp-action="Index">Chat</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-white" asp-area="" asp-controller="Documents" asp-action="Index">Documentos</a>
                        </li>
                    }
                </ul>
                @if (User!=null && User.Identity!=null && !User.Identity.IsAuthenticated)
                {
                    <ul class="navbar-nav ml-auto">
                        <partial name="_Language" />
                        <li class="nav-item" style="margin-right: 10px">
                            <a class="nav-link text-white" asp-area="" asp-controller="Login" asp-action="Index"><i class="bi bi-person"></i>  Login</a>
                        </li>
                    </ul>
                }
                else
                {
                    <ul class="navbar-nav ml-auto">
                        <partial name="_Language"/>
                        <li class="nav-item dropdown" style="margin-right: 10px">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <i class="bi bi-person"></i>  @(User.FindFirst("FirstName") != null ? User.FindFirst("FirstName").Value : "N/A")
                            </a>
                            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                                <a class="dropdown-item" asp-area="" asp-controller="Login" asp-action="Logout">Sair</a>
                            </div>
                        </li>
                    </ul>
                }
            </div>
        </nav>
        
        <div class="container">
            @RenderBody()
        </div>

        <footer class="border-top footer text-muted">
            <div class="container">
                &copy; 2024 - Chat IA - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
            </div>
        </footer>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-Fy6S3B9q64WdZWQUiU+q4/2Lc9npb8tCaSX9FK7E8HnRr0Jz8D6OP9dO5Vg3Q9ct" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.6/purify.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.0.2/marked.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
    
    <script src="~/js/site.js" asp-append-version="true"></script>
    <script src="~/js/wait.js" asp-append-version="true"></script>
    
    <script type="text/javascript">
        $(function () {
            // Esconde o loading inicial
            $('.loading').hide();
            $('#wrapper').show();

            // Intercepta cliques em links
            $('a:not([target="_blank"]):not([href^="#"]):not([href^="javascript"])').click(function(e) {
                if (this.hostname === window.location.hostname) {
                    e.preventDefault();
                    const href = $(this).attr('href');
                    
                    // Adiciona fade out
                    $('#wrapper').addClass('fade-out');
                    $('.loading').show();
                    
                    // Navega após a animação
                    setTimeout(() => {
                        window.location.href = href;
                    }, 300);
                }
            });

            // Gerencia estado ativo dos links
            function setActiveByLocation() {
                $('ul.navbar-nav').find('a[href="' + location.pathname + '"]')
                    .closest('li')
                    .addClass("active")
                    .find('a')
                    .removeClass('text-white')
                    .addClass('text-black');
            }

            // Remove fade-out quando a página carrega
            $(window).on('pageshow', function() {
                $('#wrapper').removeClass('fade-out');
                $('.loading').hide();
                setActiveByLocation();
            });

            // Gerencia submissão de formulários
            $(document).on('submit', 'form', function () {
                $('#wrapper').addClass('fade-out');
                $('.loading').show();
            });

            // Configuração inicial
            setActiveByLocation();
        });
    </script>
    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>