@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel>
@using Dynamicweb
@using Dynamicweb.Security.UserManagement

@{ 
	bool canImpersonate = UserContext.Current.GetImpersonatableUsers()?.Count() > 0;
	var currentImpersonatingUser = UserContext.Current.ImpersonatingUser;
}

@if (canImpersonate || currentImpersonatingUser != null) { 
	<div class="d-flex flex-column flex-md-row align-items-center justify-content-end gap-2 fs-7 text-center text-md-end">
		@if (Pageview?.User != null)
		{
			if (currentImpersonatingUser != null)
			{
				<div>
					<span class="fw-bold">@currentImpersonatingUser.Name</span>
					<span>
						@Translate("is signed in as")
					</span>
					<span class="fw-bold">@Pageview.User.Name</span>
				</div>
				<div class="d-flex justify-content-around gap-2">
					<span class="border-2 border-end h-auto my-1"></span>
					<a href="Default.aspx?ID=@(Pageview.ID)&DwExtranetRemoveSecondaryUser=1" class="btn btn-sm btn-link text-reset p-0 swift_sign-out-as-customer-link">@Translate("Sign out as customer")</a>
				</div> 
			}
			else if (Pageview.User != null)
			{
				<div>
					<span>@Translate("You are signed in as")</span>
					<span class="fw-bold">@Pageview.User.Name</span>
				</div>
				<div class="d-flex justify-content-around gap-2">
					@if (Model.Item.TryGetLink("Link", out Dynamicweb.Frontend.LinkViewModel customerListLink))
					{
						<span class="d-none d-md-block border-2 border-end h-auto my-1"></span>
						<a href="@customerListLink.Url" class="btn btn-sm btn-link text-reset p-0 swift_sign-in-as-customer-link">@Translate("Sign in as customer")</a>
					}
				</div>
			}
		}
	</div>
}

@if (Pageview.IsVisualEditorMode && !canImpersonate) {
    <div class="alert alert-info mt-3" role="alert">
        <span>@Translate("Impersonation bar: Edit this column to configure")</span>
    </div>
}
