@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@using Dynamicweb
@using Dynamicweb.Environment
@using System.Globalization

@{ 
	string pageTitle = Pageview.Page.GetDisplayName();
	string pageId = GetGlobalValue("Global:Page.ID");
	int signInProfilePageId = Pageview.Page.ID;
	string currentUserId = GetGlobalValue("Global:Extranet.UserID");
	string goBackToPage = Dynamicweb.Context.Current.Request.GetString("GoBackToPage"); //parameter from anonymous checkout
	string absoluteUri = Dynamicweb.Context.Current?.Request?.UrlReferrer?.AbsoluteUri != null ? Dynamicweb.Context.Current.Request.UrlReferrer.AbsoluteUri : "";
	string redirectPage = !string.IsNullOrEmpty(goBackToPage) ? "Default.aspx?Id=" + goBackToPage : absoluteUri;
	redirectPage = string.IsNullOrEmpty(goBackToPage) && !string.IsNullOrEmpty(GetString("UserManagement:User.Login.SuccessRedirectToPage")) ? GetString("UserManagement:User.Login.SuccessRedirectToPage") : redirectPage;
	var loginProvider = GetLoop("DWExtranetExternalLoginProviders");
}

<div>
	
	@if (Pageview.Area.CultureInfo.TwoLetterISOLanguageName == "da" && !string.IsNullOrEmpty(GetString($"DW_extranet_error_dk")))
	{
		<div class="alert alert-danger" role="alert">
			@GetString($"DW_extranet_error_dk")
		</div>
	}
	else if (!string.IsNullOrEmpty(GetString("DW_extranet_error_uk")))
	{
		<div class="alert alert-danger" role="alert">
			@GetString($"DW_extranet_error_uk")
		</div>
	}

	<div class="card border-0 mx-auto" style="max-width: 30rem;">
	
		<div class="card-header text-center p-4 border-bottom">
			<h4 class="display-6 m-0">@pageTitle</h4>
		</div>
		
		<div class="card-body p-4">
			<form class="grid grid-1 gap-4" method="post">
				<input type="hidden" name="ID" value="@pageId">
				<input type="hidden" name="DWExtranetUsernameRemember" value="True">
				<input type="hidden" name="DWExtranetPasswordRemember" value="True">
				<input type="hidden" name="GoBackToPage" value="@goBackToPage">
				<input type="hidden" name="LoginAction" value="Login">

				@if (!Convert.ToBoolean(Pageview.CurrentParagraph.Item["EnableUserStartPageRedirect"])) { 
					<input type="hidden" name="redirect" value="@redirectPage">
				}

				@foreach(LoopItem provider in loginProvider)
				{
					string iconPath = "/Files/IconsLoginProviders/";
					string providerName = provider.GetString("ProviderName").ToLower();
					string providerIcon = string.Empty;

					if(providerName.Contains("azure"))
					{
						providerIcon = "azure";
					}
					if(providerName.Contains("google"))
					{
						providerIcon = "google";
					}

					<div class="d-grid">
						<a class="btn btn-outline-primary btn-lg" data-dw-button="outline-primary" href="/Admin/Public/Social/ExternalLogin.aspx?action=login&providerID=@provider.GetValue("ProviderID")">
							<span class="d-flex justify-content-center align-items-center">
								<span class="icon-3 me-2">
									@ReadFile(iconPath + providerIcon + ".svg")
								</span>
								<span>@Translate("Sign in with") @provider.GetString("ProviderName")</span>
							</span>
						</a>
					</div>

					<div class="d-flex align-items-center gap-3">
						<span class="border-top flex-fill"></span>
						<span class="text-uppercase">@Translate("or")</span>
						<span class="border-top flex-fill"></span>
					</div>
				}

				<div>
					<div class="form-label fs-7 mb-0 opacity-75">@Translate("Your email")</div>
					<div class="form-floating">
						<input type="text" class="form-control" id="login-username" name="username" placeholder="@Translate("Email")" required>
						<label for="login-username">@Translate("Email")</label>
					</div>

				</div>

				<div>
					<div class="d-flex justify-content-between align-items-center">
						<div class="form-label fs-7 mb-0 opacity-75">@Translate("Your password")</div>
						<a tabindex="-1" class="form-label-link" href="/Default.aspx?id=@(signInProfilePageId)&LoginAction=Recovery" id="ForgotPasswordButton">@Translate("Forgot password?")</a>
					</div>

					<div class="form-floating">
						<input type="password" class="form-control" id="LoginPassword" name="password" placeholder="@Translate("Password")" required>
						<label for="LoginPassword">@Translate("Password")</label>
					</div>
				</div>

				<div class="form-check">
					<input class="form-check-input" type="checkbox" value="True" name="Autologin" id="RememberMe">
					<label class="form-check-label" for="RememberMe">@Translate("Keep me signed in")</label>
				</div>

				<div class="d-grid">
					<button type="submit" class="btn btn-primary btn-lg" data-dw-button="primary" id="SignInButton">@Translate("Sign in")</button>
				</div>
			</form>
		</div>
	</div>
</div>

