@using System.Security.Claims

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - PostAll</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="~/Postall.styles.css" asp-append-version="true" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
    @await RenderSectionAsync("Styles", required: false)
    <style>
        .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;
        }

    </style>
</head>
<body class="hide-body">
    <partial name="_Busy" />
    <div id="wrapper">
        <nav id="nav-bar" class="navbar navbar-expand-lg navbar-dark">
            <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">PostAll</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="Plans" asp-action="Index">Planos</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="Channels" asp-action="Index">Canais</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white" asp-area="" asp-controller="Videos" asp-action="Index">Videos</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white" asp-area="" asp-controller="OtherLogins" asp-action="Index">Sites</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link text-white" asp-area="" asp-controller="SocialMedia" asp-action="Index">Postagens</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("FullName") != null ? User.FindFirst("FullName").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>
@*                                         
                            <a class="dropdown-item" href="#">Action</a>
                            <a class="dropdown-item" href="#">Another action</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="#">Something else here</a>
*@
                        </div>
                    </li>
@* 
                    <li class="nav-item">
                        <a class="nav-link text-white" asp-area="" asp-controller="Login" asp-action="Logout">@User.FindFirst("FullName").Value
                        </a>
                    </li>
*@                        
                </ul>
        }
            </div>
        </nav>
        <div class="container">
            @RenderBody()
    @*         
            <main role="main" class="pb-3">
            </main>
     *@ 
        </div>

        <footer class="border-top footer text-muted">
            <div class="container">
                &copy; 2024 - PostAll - <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="~/js/site.js" asp-append-version="true"></script>
    <script src="~/js/wait.js" asp-append-version="true"></script>
    <script type="text/javascript">
        $(function () {
            $(document).ready(function () {
                $('.loading').hide();
                $('#wrapper').show();
                //$('body').fadeIn(1000);
                $('body').slideDown('slow');

                // 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);
                    }
                });
            });

            $('a[href="#search"]').on('click', function (event) {
                event.preventDefault();
                $('#search').addClass('open');
                $('#search > form > input[type="search"]').focus();
                inactivateActiveOption();
                searchActive();
            });

            $('#search, #search button.close').on('click keyup', function (event) {
                if (event.target == this || event.target.className == 'close' || event.keyCode == 27) {
                    $(this).removeClass('open');
                    setActiveByLocation();
                    searchInactive();
                }
            });

            $(window).on('beforeunload', function () {
                displayBusyIndicator();
            });

            $(document).on('submit', 'form', function () {
                displayBusyIndicator();
            });

            $(document).ready(function () {
                $('#wrapper').fadeIn('slow');
                $('#navbarNav a.nav-link').click(function () {
                    if ($(this).hasClass('dropdown-toggle')) {
                        return;
                    }
                    $('#wrapper').fadeOut('slow');
                });
                setActiveByLocation();
            });



            function setActiveByLocation() {
                $('ul.navbar-nav').find('a[href="' + location.pathname + '"]')
                    .closest('li')
                    .addClass("active")

                $('ul.navbar-nav').find('a[href="' + location.pathname + '"]')
                    .closest('a')
                    .removeClass('text-white')
                    .addClass('text-black');
            }

            function searchActive() {
                $('#searchLi').addClass("active");
                $('#searchLi > a')
                    .removeClass('text-white')
                    .addClass('text-black');
            }

            function searchInactive() {
                $('#searchLi').removeClass("active");
                $('#searchLi > a')
                    .removeClass('text-black')
                    .addClass('text-white');
            }

            function inactivateActiveOption() {
                $('ul.navbar-nav li.active')
                    .closest('li')
                    .removeClass("active")

                $('ul.navbar-nav').find('a[href="' + location.pathname + '"]')
                    .closest('a')
                    .removeClass('text-black')
                    .addClass('text-white');
            }

            function displayBusyIndicator() {
                //$('body').fadeOut(1000);
                $('body').slideUp('slow');
            }

            // 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();
            });

            //$(".hide-body").fadeOut(2000);
        });
    </script>
    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>
