<?php
session_start(['gc_maxlifetime' => 14400, 'cookie_httponly' => true]);

require('configuration.php');

// Already logged in
if (!empty($_SESSION['login_member'])) {
    header('Location: member_homepage.php');
    exit();
}

// Login logic
$error = '';
require('login.php');

include('member-header.php');
?>

<div class="et_pb_column et_pb_column_4_4 et_pb_column_0 et-last-child">
    <form class="login-form" method="POST">

    <?php if (!empty($error)) : ?>
        <div class="alert alert-danger mb-3">
            <?php echo htmlspecialchars($error); ?>
        </div>
    <?php endif; ?>

    <div class="form-group-ds">
        <label class="form-label-ds" for="member_email">
            Email or Username
        </label>

        <div class="input-wrapper-ds">
            <!-- icon -->

            <input
                type="text"
                id="member_email"
                name="member_email"
                class="input-ds"
                placeholder="Email or Username"
                value="<?php echo isset($_POST['member_email']) ? htmlspecialchars($_POST['member_email']) : ''; ?>"
                required>
        </div>
    </div>

    <div class="form-group-ds">
        <label class="form-label-ds" for="member_password">
            Password
        </label>

        <div class="input-wrapper-ds">
            <!-- lock icon -->

            <input
                type="password"
                id="member_password"
                name="member_password"
                class="input-ds has-icon-right"
                placeholder="Enter Your Password"
                required>

            <button
                type="button"
                class="input-icon-right"
                onclick="togglePassword()">
                ...
            </button>
        </div>
    </div>

    <div class="form-options">
        <label class="checkbox-ds">
            <input type="checkbox" name="remember">
            <span>Remember Me</span>
        </label>

        <a href="forgot_password.php" class="link-ds">
            Forgot Password?
        </a>
    </div>

    <button
        type="submit"
        name="submit"
        value="1"
        class="btn-login btn-ds-primary">

        <!-- svg -->

        Log In
    </button>

</form>
</div>

<?php include('member-footer.php'); ?>