@inherits LayoutComponentBase
@using Front.Services
@using Shared.DTOs
@inject ILocalStorageService Storage;
@inject UserAuthenticationDTO userinfo
@inject HttpClient _hc
@inject NavigationManager nav
@inject localService localserv;
@inject Fixedvalues fv;
<Modal @ref="modal" />
<HeadContent>
    <link rel="canonical" href="#">
    <!-- Favicon -->
    <link rel="icon" type="image/png" href="img/logo/siyahe.png" />
    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Public+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">
    <!-- Icons. Uncomment required icon fonts -->
    <link rel="stylesheet" href="assets/vendor/fonts/boxicons.css" />
    <link href='assets/css/boxicons.min.css' rel='stylesheet'>
    <!-- Core CSS -->
    <link rel="stylesheet" href="assets/vendor/css/core.css" class="template-customizer-core-css" />
    <link rel="stylesheet" href="assets/vendor/css/theme-default.css" class="template-customizer-theme-css" />
    <link rel="stylesheet" href="assets/css/demo.css" />
    <link rel="stylesheet" href="assets/css/chatstyle.css" />
    <!-- Vendors CSS -->
    <link rel="stylesheet" href="assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.css" />
    <link rel="stylesheet" href="assets/vendor/libs/apex-charts/apex-charts.css" />
    <!-- Page CSS -->
    <!-- Helpers -->
    <script src="assets/vendor/js/helpers.js"></script>
    <!--! Template customizer & Theme config files MUST be included after core stylesheets and helpers.js in the <head> section -->
    <!--? Config:  Mandatory theme config file contain global vars & default theme options, Set your preferred theme option in this file.  -->
    <script src="assets/js/config.js"></script>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async="async" src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"></script>
    <script>
        window.dataLayer = window.dataLayer || [];

        function gtag() {
            dataLayer.push(arguments);
        }
        gtag('js', new Date());
        gtag('config', 'GA_MEASUREMENT_ID');
    </script>

    <!-- Core JS -->
    <!-- build:js assets/vendor/js/core.js -->
    <script src="assets/vendor/libs/jquery/jquery.js"></script>
    <script src="assets/vendor/libs/popper/popper.js"></script>
    <script src="assets/vendor/js/bootstrap.js"></script>
    <script src="assets/vendor/libs/perfect-scrollbar/perfect-scrollbar.js"></script>
    <script src="assets/vendor/js/menu.js"></script>
    <!-- endbuild -->
    <!-- Vendors JS -->
    <script src="assets/vendor/libs/apex-charts/apexcharts.js"></script>
    <!-- Main JS -->
    <script src="assets/js/main.js"></script>
    @* <!-- Page JS -->
    <script src="assets/js/dashboards-analytics.js"></script> *@
    <!-- Place this tag in your head or just before your close body tag. -->
    <script src="assets/vendor/js/buttons.js"></script>
</HeadContent>
<!-- Layout wrapper -->
<div class="layout-wrapper layout-content-navbar">
    <div class="layout-container">
        <!-- Menu -->
        <aside id="layout-menu" class="layout-menu menu-vertical menu bg-menu-theme">
            <div class="app-brand demo ">
                <a href="Panel" class="app-brand-link">
                    <span style="color:black" class="app-brand-text demo menu-text fw-bolder ms-2">سامانه مُؤدیٰران</span>
                </a>
                <a href="javascript:void(0);" class="layout-menu-toggle menu-link text-large mr-auto d-block d-xl-none">
                    <i class="bx bx-chevron-right bx-sm align-middle"></i>
                </a>
            </div>
           <PanelNavMenu />
        </aside>
        <!-- / Menu -->
        <!-- Layout container -->
        <div class="layout-page">
            <!-- Navbar -->
            <nav class="layout-navbar container-xxl navbar navbar-expand-xl navbar-detached align-items-center bg-navbar-theme" id="layout-navbar">
                <div class="layout-menu-toggle navbar-nav align-items-xl-center me-3 me-xl-0 d-xl-none">
                    <a class="nav-item nav-link px-0 me-xl-4" href="javascript:void(0)">
                        <i class="bx bx-menu bx-sm"></i>
                    </a>
                </div>
                <div class="d-flex">
                    <div class="avatar flex-shrink-0">
                        <img @onclick="CreditDocuments" src="assets/img/icons/unicons/wallet.png" alt="User">
                    </div>
                    <div>
                        <small class="text-muted d-block">موجودی</small>
                        <div class="d-flex align-items-center">
                            <h6 class="mb-0 me-1">@userinfo.Company.Credit.ToString("N0")<span style="font-size: 14px">ریال</span></h6>
                        </div>
                    </div>
                </div>

                <div class="navbar-nav-right d-flex align-items-center" id="navbar-collapse">
                  
                    <ul class="navbar-nav flex-row align-items-center mr-auto f-ir">
                        <!-- Place this tag where you want the button to render. -->
                        <li class="nav-item lh-1 me-3 f-ir">
                            <span class="fw-semibold d-block">@userinfo.Company.Name</span>
                        </li>
                        <!-- User -->
                        <li class="nav-item navbar-dropdown dropdown-user dropdown">
                            <a class="nav-link dropdown-toggle hide-arrow" href="javascript:void(0);" data-bs-toggle="dropdown">
                                <div class="avatar avatar-online">
                                    @{
                                        string _src = "assets/img/avatars/1.png";
                                        if (userinfo.Company.Logo != null)
                                            _src = "data:image/jpeg;base64," + @userinfo.Company.Logo;

                                    }
                                    <img src=@_src alt class="w-px-40 h-auto rounded-circle">
                                </div>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end new-style-13">
                               
                                <li>
                                    <NavLink class="dropdown-item" href="Profile">
                                        <i class="bx bx-user me-2"></i>
                                        <span class="align-middle">پروفایل من</span>
                                    </NavLink>
                                </li>
                              
                            
                                <li>
                                    <div class="dropdown-divider"></div>
                                </li>
                                <li>   <a class="dropdown-item">
                                        <i class="bx bx-power-off me-2"></i>
                                        <NavLink style="cursor:pointer" onclick="@Logout">

                                            <span style="color:red;">خروج</span>

                                        </NavLink>
                             </a>
                                </li>
                            </ul>
                        </li>

                    
                        <!--/ User -->
                        @if (countnot > 0)
                        {
                            <li class="nav-item lh-1 me-3 f-ir">
                                <Button Type="ButtonType.Button" @onclick="ShowNotifications" Color="ButtonColor.None">
                                    <Badge Color="BadgeColor.Danger"><Icon Name="IconName.MegaphoneFill" /> @countnot</Badge>
                                </Button>
                            </li>
                        }
                        
                    </ul>
                </div>
            </nav>
            <!-- / Navbar -->
            <!-- Content wrapper -->
            <div class="content-wrapper">
                <!-- Content -->
                <div class="container-xxl flex-grow-1 container-p-y">
        @Body

          </div>
                <!-- / Content -->
                <!-- Footer -->
                <footer class="content-footer footer bg-footer-theme">
                    <div class="container-xxl d-flex flex-wrap justify-content-between py-2 flex-md-row flex-column">
                        <div class="mb-2 mb-md-0">
                            @if (@fv.dashBoard != null)
                            {
                                <span>آخرین ورود : @fv.dashBoard?.LastLoginDate</span>
                            }
                         
                        </div>
                         <div>
                            <NavLink style="cursor:pointer" onclick="@Logout">
                                <span style="color:red;">خروج</span>
                            </NavLink>
                        </div> 
                    </div>
                </footer>
                <!-- / Footer -->
                <div class="content-backdrop fade"></div>
            </div>
            <!-- Content wrapper -->
        </div>
        <!-- / Layout page -->
    </div>
    <!-- Overlay -->
    <div class="layout-overlay layout-menu-toggle"></div>
</div>

@code {
    public int countnot = 0;
    private Modal modal = default!;
   // public DashBoardDTO? dashBoard { get; set; }
    protected override async Task OnInitializedAsync()
    {
      await  fv.SetUlr("Panel");

        if (!await localserv.OnlineUser())
            nav.NavigateTo("/");

        await fv.LoadDashBoard();
        if (fv.dashBoard != null)
            countnot = fv.dashBoard.Notifications.Count();
        await base.OnInitializedAsync();
    }
}
@functions {
    public async Task CallBack(int count)
    {
        countnot = count;
    }
    public async Task CreditDocuments()
    {
        var parameters = new Dictionary<string, object>();
       
        await modal.ShowAsync<Front.CUSComponent.CreditDocuments>(title: "تراکنش ها", parameters: parameters);
    }
    public async Task ShowNotifications()
    {
       // dashBoard = await fv.GetDashBoard();
        var parameters = new Dictionary<string, object>();
        parameters.Add("items", fv.dashBoard?.Notifications);
        parameters.Add("OnMultipleOfThree", EventCallback.Factory.Create<int>(this, CallBack));
        await modal.ShowAsync<Front.CUSComponent.Notifications>(title: "اطلاعیه ها", parameters: parameters);


    }
    private async Task Logout()
    {
        _hc.DefaultRequestHeaders.Clear();
        await Storage.RemoveItem("token");
        userinfo.Token = "";
        nav.NavigateTo("/");
    }
}