@inject Grand.Business.Core.Interfaces.Common.Directory.IGroupService  groupService
@inject IWorkContext workContext
@inject IPageHeadBuilder pagebuilder
@inject Grand.Business.Core.Interfaces.Common.Security.IPermissionService permissionService
@{
    var registerUrl = Url.RouteUrl("Register", new { returnUrl = this.Context.Request.Query["returnUrl"] });
    var isAuthenticated = await groupService.IsRegistered(workContext.CurrentCustomer);
    var isCustomerImpersonated = workContext.OriginalCustomerIfImpersonated != null;
    var isAdminAccess = await permissionService.Authorize(Grand.Business.Core.Utilities.Common.Security.StandardPermission.AccessAdminPanel);
}

@await Component.InvokeAsync("Widget", new { widgetZone = "header_links_before" })
<div>
    @if (isCustomerImpersonated)
    {
        <a class="btn btn-outline-secondary w-100 mb-2" href="@Url.RouteUrl("Logout")" title="@Loc["Account.ImpersonatedAs.Finish.Hint"]">
            <b-icon icon="door-closed"></b-icon>
            <span class="text text-uppercase ml-3">@string.Format(Loc["Account.ImpersonatedAs"], workContext.CurrentCustomer.Email ?? "GUEST")</span>
        </a>
    }
    @if (isAuthenticated)
    {
        @if (isAdminAccess)
        {
            <a class="btn btn-outline-secondary w-100 mb-2" href="@Url.Content("~/Admin")">
                <b-icon icon="gear"></b-icon>
                <span class="text text-uppercase ml-3">@Loc["admin"]</span>
            </a>
        }
        @if (!string.IsNullOrEmpty(pagebuilder.EditPageUrl))
        {
            <a target="_blank"  class="btn btn-outline-secondary w-100 mb-2" href="@pagebuilder.EditPageUrl">
                <b-icon icon="wrench"></b-icon>
                <span class="text text-uppercase ml-3">@Loc["edit"]</span>
            </a>
        }
        <a class="btn btn-outline-secondary w-100 mb-2" href="@Url.RouteUrl("CustomerInfo")">
            <b-icon icon="person"></b-icon>
            <span class="text text-uppercase ml-3">@Loc["Account.MyAccount"]</span>
        </a>
        <a class="btn btn-outline-secondary w-100 mb-2" href="@Url.RouteUrl("CustomerOrders")">
            <b-icon icon="handbag"></b-icon>
            <span class="text text-uppercase ml-3">@Loc["Account.CustomerOrders"]</span>
        </a>
        <a class="btn btn-outline-secondary w-100 mb-2" href="@Url.RouteUrl("Logout")">
            <b-icon icon="lock"></b-icon>
            <span class="text text-uppercase ml-3">@Loc["Account.Logout"]</span>
        </a>
    }
    else
    {
        <span class="d-flex h5 justify-content-center mb-3 w-100">@Loc["Account.Login.ReturningCustomer"] / @Loc["SideBar.NewCustomer"]</span>
        <div class="d-inline-flex flex-sm-nowrap flex-wrap w-100">
            <a class="btn btn-secondary w-100 mx-1 mb-2" href="@Url.RouteUrl("Login")">
                <b-icon icon="shield-lock"></b-icon>
                <span class="text text-uppercase ml-sm-3 ml-2">@Loc["Account.Login"]</span>
            </a>
            <a class="btn btn-secondary w-100 mx-1 mb-2" href="@registerUrl">
                <b-icon icon="person"></b-icon>
                <span class="text text-uppercase ml-sm-3 ml-2">@Loc["Account.Register"]</span>
            </a>
        </div>
        <div class="text-center generalMarginSupporter">
            @Loc["Account.Login.NewCustomerText"]
        </div>
    }
</div>
@await Component.InvokeAsync("Widget", new { widgetZone = "header_links_after" })

