<?php
if (!defined('ABSPATH')) {
    exit;
}
$validate_with_recaptcha =  CHAMA_RECAPTCHA_SITE_KEY && CHAMA_RECAPTCHA_SECRET_KEY;
$registration_url = CHAMA_REGISTRATION_URL;
$redirect_url = '';
$raw_url      = filter_input(INPUT_GET, 'redirect_url', FILTER_SANITIZE_URL);
if ($raw_url) {
    $redirect_url = urlencode($raw_url); 
    $registration_url = add_query_arg(
        array(
            'redirect_url' => $redirect_url, 
        ),
        CHAMA_REGISTRATION_URL
    );
}
?>
<div class="chama-account-page-wrapper">
    <div class="chama-form-wrapper">
	<div class="chama-form-header">&#x1F512; Log in to your account</div>
    <div class="chama-form-content">
	<?php
// show any error messages after form submission
chama_show_error_messages();?>
    <form id="chama-login-form" class="chama-form" action="" method="POST">

	<p>
					<label for="chama_username">Username/Email</label>
					<input name="chama_username" id="chama_username" class="required" type="text" required data-msg="Please enter your username or email"/>
				</p>
				<p>
					<label for="chama_password">Password</label>
					<input name="chama_password" id="chama_password" class="required" type="password" required data-msg="Please enter your password"/>
				</p>
				<p>
					<?php if ($redirect_url): ?>
					<input type="hidden" name="chama_redirect_url" value="<?php echo esc_attr($redirect_url); ?>"/>
					<?php endif;?>
					<?php if ($validate_with_recaptcha): ?>
						<div class="g-recaptcha"
						data-sitekey="<?php echo esc_attr(CHAMA_RECAPTCHA_SITE_KEY); ?>"
						data-badge="inline" data-size="invisible"
						data-callback="setResponse"></div>
						<input type="hidden" id="chama-captcha-response" name="chama-captcha-response" />

					<?php endif;?>
					<input type="hidden" name="chama_action" value="login"/>
					<input type="hidden" name="chama_login_nonce" value="<?php echo esc_attr(wp_create_nonce('chama-login-nonce')); ?>"/>
					<input id="chama-login-submit" class="chama-button chama-account-submit" type="submit" value="Log in"/>
				</p>

		</form>
		<p>Don't have an account? <a href="<?php echo esc_url($registration_url); ?>">Sign up here</a><br/>
		<a href="<?php echo esc_url(CHAMA_FORGOT_PASSWORD_URL); ?>">Forgot password?</a></p>
		</div>

</div>
</div>
   