<div class="ui container fluid{{if .LinkAccountMode}} icon{{end}}">
	<h4 class="ui top attached header center">
		{{if .LinkAccountMode}}
			{{ctx.Locale.Tr "auth.oauth_signup_title"}}
		{{else}}
			{{ctx.Locale.Tr "sign_up"}}
		{{end}}
	</h4>
	<div class="ui attached segment">
		{{if .IsFirstTimeRegistration}}
			<p>{{ctx.Locale.Tr "auth.sign_up_tip"}}</p>
		{{end}}
		{{if or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeRegister)}}
			{{template "base/alert" .}}
			{{if .PendingAccountRequestMessage}}
				<div class="ui info message">
					<div class="tw-flex tw-items-center tw-gap-2 tw-flex-wrap">
						<p class="tw-my-0">{{.PendingAccountRequestMessage}}</p>
						{{if .AccountRequestValidationMailAttemptStatus}}
							<span {{if eq .AccountRequestValidationMailAttemptStatus "succeeded"}}class="tw-text-green-600"{{else}}class="tw-text-red-600"{{end}}>{{if eq .AccountRequestValidationMailAttemptStatus "succeeded"}}✔{{else}}❌{{end}}</span>
							<span>{{DateUtils.FullTime .AccountRequestValidationMailAttemptUnix}}</span>
						{{end}}
					</div>
					{{if .ShowResendAccountRequestButton}}
						<div class="tw-mt-3 tw-mb-4 tw-flex tw-items-center tw-gap-3 tw-flex-wrap">
							<span>{{ctx.Locale.Tr "auth.account_request_resend_prompt"}}</span>
							<form class="ui form" action="{{AppSubUrl}}/user/sign_up/resend" method="post">
								{{.CsrfTokenHtml}}
								<input type="hidden" name="email" value="{{.PendingAccountRequestEmail}}">
								<input type="hidden" name="user_name" value="{{.user_name}}">
								<input type="hidden" name="password" value="{{.password}}">
								<input type="hidden" name="retype" value="{{.retype}}">
								<input type="hidden" name="source" value="signup">
								<button class="ui tiny js-account-request-resend-button {{if eq .AccountRequestResendButtonState "success"}}is-success{{end}} button" data-mail-action-ui="inline-v2" style="{{if eq .AccountRequestResendButtonState "success"}}background: var(--color-green); color: var(--color-white); border-color: var(--color-green);{{else if eq .AccountRequestResendButtonState "failed"}}background: var(--color-red); color: var(--color-white); border-color: var(--color-red);{{else}}background: var(--color-primary); color: var(--color-primary-contrast); border-color: var(--color-primary);{{end}}" type="submit">{{ctx.Locale.Tr "auth.account_request_resend_button"}}</button>
							</form>
						</div>
					{{end}}
					<p class="tw-mt-0 tw-mb-0 tw-text-muted">{{ctx.Locale.Tr "auth.account_request_spam_hint"}}</p>
				</div>
			{{end}}
		{{end}}
		<form class="ui form" action="{{.SignUpLink}}" method="post">
			{{if .DisableRegistration}}
				<p>{{ctx.Locale.Tr "auth.disable_register_prompt"}}</p>
			{{else}}
				<div class="required field {{if and (.Err_UserName) (or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeRegister))}}error{{end}}">
					<label for="user_name">{{ctx.Locale.Tr "username"}}</label>
					<input id="user_name" type="text" name="user_name" value="{{.user_name}}" autofocus required>
				</div>
				<div class="required field {{if .Err_Email}}error{{end}}">
					<label for="email">{{ctx.Locale.Tr "email"}}</label>
					<input id="email" name="email" type="email" value="{{.email}}" required>
				</div>

				{{if not .DisablePassword}}
					<div class="required field {{if and (.Err_Password) (or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeRegister))}}error{{end}}">
						<label for="password">{{ctx.Locale.Tr "password"}}</label>
						<div class="ui input js-password-toggle-group" data-global-init="initPasswordVisibilityToggle" data-show-label="{{ctx.Locale.Tr "auth.show_password"}}" data-hide-label="{{ctx.Locale.Tr "auth.hide_password"}}" data-confirm-field-selector=".js-password-toggle-confirm-field" data-confirm-input-selector=".js-password-toggle-confirm">
							<input id="password" name="password" type="password" value="{{.password}}" autocomplete="new-password" required class="js-password-toggle-source">
						</div>
					</div>
					<div class="required field js-password-toggle-confirm-field {{if and (.Err_Password) (or (not .LinkAccountMode) (and .LinkAccountMode .LinkAccountModeRegister))}}error{{end}}">
						<label for="retype">{{ctx.Locale.Tr "re_type"}}</label>
						<input id="retype" name="retype" type="password" value="{{.retype}}" autocomplete="new-password" required class="js-password-toggle-confirm">
					</div>
				{{end}}

				{{template "user/auth/captcha" .}}

				<div class="inline field">
					<button class="ui primary button tw-w-full">
						{{if .LinkAccountMode}}
							{{ctx.Locale.Tr "auth.oauth_signup_submit"}}
						{{else}}
							{{ctx.Locale.Tr "auth.create_new_account"}}
						{{end}}
					</button>
				</div>
			{{end}}
			{{$showExternalAuthMethods := or .OAuth2Providers .EnableOpenIDSignIn .EnableSSPI}}
			{{if $showExternalAuthMethods}}
				<div class="divider divider-text">{{ctx.Locale.Tr "sign_in_or"}}</div>
				{{template "user/auth/external_auth_methods" .}}
			{{end}}
		</form>
	</div>
</div>

<div class="ui container fluid">
	{{if not .LinkAccountMode}}
	<div class="ui attached segment header top tw-flex tw-flex-col tw-items-center">
		<div class="field">
			<span>{{ctx.Locale.Tr "auth.already_have_account"}}</span>
			<a href="{{AppSubUrl}}/user/login">{{ctx.Locale.Tr "auth.sign_in_now"}}</a>
		</div>
	</div>
	{{end}}
</div>
{{if eq .AccountRequestResendButtonState "success"}}
	<script>
		window.setTimeout(() => {
			for (const button of document.querySelectorAll('.js-account-request-resend-button.is-success')) {
				button.classList.remove('is-success');
				button.style.background = 'var(--color-primary)';
				button.style.color = 'var(--color-primary-contrast)';
				button.style.borderColor = 'var(--color-primary)';
			}
		}, 5000);
	</script>
{{end}}
