<?php

session_start();

if (isset($_SESSION['user_id'])) {
	if ($_SESSION['user_level'] == 1) {
		header("location:admin/index.php");
	}
}

$login = 0;

if (isset($_GET['login'])) {
    $login = $_GET['login'];
}

if ($login == 1) {
    $komen = "Silahkan Login Ulang, Cek Email dan Password Anda!!";
}

if ($login == 2) {
    $komen = "Register akun gagal, Password yang anda masukkan tidak sama!!";
}

if ($login == 3) {
    $komen = "Register akun gagal, Anda sudah mendaftarkan akun dengan email ini!!";
}

if ($login == 4) {
    $komen = "Register akun sukses";
}

if ($login == 5) {
    $komen = "Register akun gagal";
}

?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<script src="https://kit.fontawesome.com/a076d05399.js"></script>
	<link rel="stylesheet" href="style_login.css">
	<title>Sewa Tenda</title>
</head>
<body>
	<div class="login-page">
		<div class="wrapper">
			<div class="title-text">
				<div class="title login">Login Form</div>
				<div class="title signup">Signup Form</div>
			</div>
			<?php if (isset($komen)) { echo "<div class='alert alert-danger alert-dismissable'><h4><i class='icon fa fa-ban'></i> Login failed! </h4>".$komen."</div>"; } ?>
			<div class="form-container">
				<div class="slide-controls">
					<input type="radio" name="slider" id="login" checked>
					<input type="radio" name="slider" id="signup">
					<label for="login" class="slide login">Login</label>
					<label for="signup" class="slide signup">Signup</label>
					<div class="slide-tab"></div>
				</div>
				<div class="form-inner">
					<form action="cek-login.php" method="post" class="login">
						<div class="field">
							<input type="text" name="email" placeholder="Email Address" required>
						</div>
						<div class="field">
							<input type="password" name="password" placeholder="Password" required>
						</div>
						<div class="pass-link">
							<a href="#">Forgot Password?</a>
						</div>
						<div class="field">
							<input type="submit" value="Login">
						</div>
						<div class="signup-link">Not a member? <a href="#">Signup now</a></div>
					</form>

					<form action="cek-signup.php" method="post" class="signup">
						<div class="field">
							<input type="text" name="nama" placeholder="Nama Lengkap" required>
						</div>
						<div class="field">
							<input type="text" name="email" placeholder="Email" required>
						</div>
						<div class="field">
							<input type="password" name="password" placeholder="Password" required>
						</div>
						<div class="field">
							<input type="password" name="cpassword" placeholder="Konfirmasi Password" required>
						</div>
						<div class="field">
							<input type="submit" value="Signup">
						</div>
					</form>
				</div>
			</div>
		</div>
		<script>
			const loginForm = document.querySelector("form.login");
			const signupForm = document.querySelector("form.signup");
			const loginBtn = document.querySelector("label.login");
			const signupBtn = document.querySelector("label.signup");
			const signupLink = document.querySelector(".signup-link a");
			const loginText = document.querySelector(".title-text .login");
			const signupText = document.querySelector(".title-text .signup");

			signupBtn.onclick = (()=>{
				loginForm.style.marginLeft = "-50%";
				loginText.style.marginLeft = "-50%";
			});

			loginBtn.onclick = (()=>{
				loginForm.style.marginLeft = "0%";
				loginText.style.marginLeft = "0%";
			});

			signupLink.onclick = (()=>{
				signupBtn.click();
				return false;
			});
		</script>
	</div>
</body>
</html>