/**
 * @file    login.js
 * @brief   Login 登录页面
 */


Router.register('#login', function(c) {
	c.innerHTML = '<div class="login-wrap"><div class="login-box">'
		+ '<h1>' + I18n.t('login.title') + '</h1>'
		+ '<div class="form-group"><label class="form-label">' + I18n.t('login.username') + '</label><input class="form-input" id="login-user" placeholder="admin" autofocus></div>'
		+ '<div class="form-group"><label class="form-label">' + I18n.t('login.password') + '</label><input class="form-input" id="login-pass" type="password" placeholder="\u2022\u2022\u2022\u2022\u2022\u2022"></div>'
		+ '<button class="btn btn-primary" onclick="doLogin()">' + I18n.t('login.signin') + '</button>'
		+ '</div></div>';
});

function doLogin()
{
	var u = document.getElementById('login-user').value.trim();
	var p = document.getElementById('login-pass').value.trim();
	if (u === 'admin' && p === 'admin')
	{
		localStorage.setItem('rtu_logged_in', '1');
		window.location.hash = '#dashboard';
	}
	else
	{
		toast(I18n.t('login.error'), 'error');
	}
}

document.addEventListener('keydown', function(e) {
	if (e.key === 'Enter' && Router.currentHash === '#login')
	{
		doLogin();
	}
});
