<?php
if (!defined('ABSPATH')) {
    exit;
}
$login_url = CHAMA_LOGIN_URL;
$validate_with_recaptcha =  CHAMA_RECAPTCHA_SITE_KEY && CHAMA_RECAPTCHA_SECRET_KEY;
$redirect_url = '';
$raw_url      = filter_input(INPUT_GET, 'redirect_url', FILTER_SANITIZE_URL);
if ($raw_url) {
    $redirect_url = urlencode($raw_url);
    $login_url = add_query_arg(
        array(
            'redirect_url' => $redirect_url, 
        ),
        CHAMA_LOGIN_URL
    );
}
?>
<div class="chama-account-page-wrapper">
    <div class="chama-form-wrapper">
    <div class="chama-form-header">&#x1F512; Register your account</div>
    <div class="chama-form-content">

	<?php
// show any error messages after form submission
chama_show_error_messages();?>
    <form id="chama-registration-form" class="chama-form" action="" method="POST">

				<p>
					<label for="chama_username"><?php esc_html_e('Username', 'chama');?></label>
					<input name="chama_username" id="chama_username" class="required" type="text" required data-msg="Please enter your username"/>
				</p>
				<p>
					<label for="chama_email"><?php esc_html_e('Email', 'chama');?></label>
					<input name="chama_email" id="chama_email" class="required" type="email" required data-msg="Please enter your email" data-msg-email="Enter a valid email"/>
				</p>

				<p>
					<label for="password"><?php esc_html_e('Password', 'chama');?></label>
					<input name="chama_password" id="password" class="required" type="password" required data-msg="Please enter your password"/>
				</p>
				<p>
					<label for="password_again"><?php esc_html_e('Password Again', 'chama');?></label>
					<input name="chama_password_confirm" id="password_again" class="required" type="password" required data-msg="Please enter your password again" data-msg-equalto="Passwords must match!" />
				</p>
				<p class="chama-hint">Tip: The password should be at least twelve characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ &amp; ).</p>
				<p>
				<span id="password-strength"></span>
				</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="register"/>
					<input type="hidden" name="chama_register_nonce" value="<?php echo esc_attr(wp_create_nonce('chama-register-nonce')); ?>"/>
					<input type="submit" class="chama-button chama-account-submit" value="<?php esc_attr_e('Register', 'chama');?>"/>
				</p>
				<p class="chama-instructions chama-instructions-info">
	Please note that you will have to check your email and verify your account. You must click on the confirmation URL that will be sent to your link before you gain full access to the content on this website.
</p>
		</form>
		<p>Already have an account? <a href="<?php echo esc_url($login_url); ?>">log in here</a>
		</p>
		</div>

</div>
</div>