{% 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">
				Sign In
			</h1>		
			<p class="text" style="">
				Enter your username & password to sign in.
			</p>
			<input id="username" type="username" placeholder="Username" class="input" onkeydown="if (event.keyCode==13) { __sign_in__() }" style="margin-bottom: 5px;">
			<input id="password" type="password" autocomplete="off" placeholder="Your Passphrase" class="input" onkeydown="if (event.keyCode==13) { __sign_in__() }" 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="/accounts/reset/" class="empty_a">
					Reset Password
				</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%;">
					<a href="/accounts/signup/" class="empty_a">
						Sign Up
					</a>
				</button>
				<div style="width: 2%; height: 1%;"></div>
				<button class="button" style="width: 49%;" onclick="__sign_in__()">
					<a href="#" class="empty_a">
						Sign In
					</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">
	
	// default username.
	if (localStorage.getItem("USERNAME") != null) {
		document.getElementById("username").value = localStorage.getItem("USERNAME")
	}
	// create encryption request.
	function __sign_in__() {
		request("/requests/accounts/signin/", {
				username:document.getElementById("username").value.toLowerCase().replaceAll(" ",""), 
				password:document.getElementById("password").value, 
				code:null,
				response: document.getElementById("response"),
				loader: document.getElementById("loader"),
			},
			function(response) {
				if (response.error == null) {
					localStorage.setItem("USERNAME", document.getElementById("username").value.toLowerCase().replaceAll(" ",""))
					location.href = "/"
				}
			},
		)
	}

</script>

{% endblock %}