<?php
require 'login_header.php';
?>
<div class="login">
    <center>
		<img class="login-logo" src="https://app.anesoft.com/images/logo/logo-new-dark.png">
		<?php /* <h1>Log In</h1> */ ?>
	</center>
    <div class='red error'>
        <?php
        if (isset($_SESSION['errors'])) {
            foreach ($_SESSION['errors'] as $session_key => $session_value) {
                echo htmlspecialchars($session_value) . "<br>";
            }
            unset($_SESSION['errors']);
        }
        ?>
    </div>
    
    <form name="login" action="<?php echo BASEURL; ?>actions/user/user_a.php" method="post" onsubmit="return validateForm()">
        <input type="hidden" name="action" value="login">
        <table>
            <tr>
                <?php /* <td><b>Email</b></td> */ ?>
                <td><input type="email" name="email" id="email" value="<?php echo (isset($_SESSION['session']['email'])) ? htmlspecialchars($_SESSION['session']['email']) : ''; ?>" placeholder="Enter your email" required></td>
            </tr>
            <tr>
                <?php /* <td><span class="light-text">Password</span></td> */ ?>
                <td><input type="password" name="pass" id="pass" value="" autocomplete="off" placeholder="Enter your password" required></td>
            </tr>
            <tr>
				<?php /* <td colspan="1" style="position: absolute; margin-top: 14px;">
					<input type="checkbox" name="remember_me" id="remember_me" style="width: 25px;">
					<label for="remember_me">Keep me logged in</label>
				</td> */ ?>
                <td colspan="2">
                    <button type="submit">Login</button>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="link" style="position: absolute; margin: 10px 0 0 44px;">
                        <center><a href="<?php echo BASEURL; ?>register.php">Not registered? Click here to register</a></center>
                    </div>
                </td>
			</tr>
        </table>
    </form>
</div>

<script>
function validateForm() {
    var email = document.getElementById('email').value;
    var pass = document.getElementById('pass').value;
    if (email == "" || pass == "") {
        alert("Both email and password must be filled out");
        return false;
    }
    console.log("Form submitted with email: " + email);
    return true;
}
</script>

<?php
require 'login_footer.php';
?>
