{% extends 'defaults/html/base.html' %}
{% load static %}
{% block content %}

<!-- JS -->
<script type="text/javascript">
	toggle_topbar("hide")
	toggle_leftbar("hide")
	toggle_rightbar("hide")
	//if ("{{USER.username|default:'None'}}" != "None") {location.href = "/"}
</script>

<!-- CONTENT -->
<div class="full_window_centered">
	<img src="{% static 'favicon.png' %}" width="45px" height="45px" style="display: block; margin: 0 auto; margin-bottom: 35px;">

	<!-- SIGN UP -->
	<div class="widget_container">
		<div class="widget_child" style="padding-left: 5px; padding-right: 5px;">
			<h1 class="title">
				Activate Your Account
			</h1>		
			<p class="text" style="">
				Enter the verification code sent to your email address to activate your account.
			</p>
			<input id="code" type="text" placeholder="Verification Code" class="input" onkeydown="if (event.keyCode==13) { __activate_account__() }" style="margin-bottom: 5px;">
			<p class="text" style="font-size: 12px; text-align: right; padding: 0px 20px 0px 20px; margin: 10px 0px 5px 0px;">
				<a href="#" class="empty_a" onclick="__resend_email__()">
					Resend Activation Email
				</a>
			</p>
			<p class="text" id="response" style="display: none; font-size: 12px; overflow: scroll;"></p>
			<div class="loader" id="loader" style="transform: scale(0.33); display: block; margin: 0 auto; display: none;"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
			<div style="display: flex; padding-top: 10px;">
				<button class="button" style="width: 49%;" onclick="sign_out()">
					<a href="#" class="empty_a">
						Sign Out
					</a>
				</button>
				<div style="width: 2%; height: 1%;"></div>
				<button class="button" style="width: 49%;" onclick="__activate_account__()">
					<a href="#" class="empty_a">
						Activate
					</a>
				</button>
			</div>
		</div>
	</div>

	<h1 class="text_reversed" style="font-size: 8px; font-weight: 400; margin-top: 35px;">
		© 2020 VanDenBerghInc. All Rights Reserved.
	</h1>
</div>

<!-- JAVASCRIPT -->
<script type="text/javascript">

	// resend activation email.
	var USERNAME = "{{USER.username}}"
	var response_element = document.getElementById("response")
	function __resend_email__() {
		try {
			request("/requests/accounts/send_code/", {
				response: response_element,
				loader:document.getElementById("loader"),
				username:USERNAME,
				mode:"activation",
			})
		} catch(e) {
			response_element.style.display = "block"
			response_element.style.color = "{{COLORS.red}}"
			response_element.innerHTML = "Refresh the web page."
		}
	}

	// create encryption request.
	function __activate_account__() {
		var response_element = document.getElementById("response")
		request("/requests/accounts/activate/", {
			response: response_element,
			loader:document.getElementById("loader"),
			username:USERNAME,
			code:document.getElementById("code").value,
		}, function(response) {
			if (response.error == null) {
				location.href = "/"
			}
		})
	}

</script>

{% endblock %}