<?php echo Wo_LoadPage('welcome/welcome-header');?>
<div class="wrapper">
	<div class="container">
		<div class="row login">
			<div class="col-md-4"></div>
			<div class="col-md-4">
				<div class="sun_welcome_heading">
					<h1><?php echo $wo['lang']['forgot_your_password']?></h1>
				</div>
				<?php
					$allow_switch = false;
					if ($wo['config']['sms_provider'] == 'twilio') {
						if( $wo['config']['sms_twilio_username'] !== "" AND  $wo['config']['sms_twilio_password'] !== "" ){
							if( $wo['config']['emailValidation'] == 1 ) {
								if( $wo['config']['sms_or_email'] == "sms" ) {
									$allow_switch = true;
								}
							}
						}
					} else if ($wo['config']['sms_provider'] == 'bulksms') {
						if( $wo['config']['sms_username'] !== "" AND  $wo['config']['sms_password'] !== "" ){
							if( $wo['config']['emailValidation'] == 1 ) {
								if( $wo['config']['sms_or_email'] == "sms" ) {
									$allow_switch = true;
								}
							}
						}
					} else if ($wo['config']['sms_provider'] == 'infobip') {
						if( $wo['config']['infobip_api_key'] !== "" AND  $wo['config']['infobip_base_url'] !== "" ){
							if( $wo['config']['emailValidation'] == 1 ) {
								if( $wo['config']['sms_or_email'] == "sms" ) {
									$allow_switch = true;
								}
							}
						}
					}
				?> 

				<?php if( $allow_switch ){ ?>
					<form  class="x_chooser">
						<div class="login_signup_combo">
							<div class="signup__">
								<button type="button" class="btn btn-main" id="recover_password_by_email"><?php echo $wo['lang']['recover_password_by_email']?></button>&nbsp;&nbsp;
								<button type="button" class="btn btn-main" id="recover_password_by_sms"><?php echo $wo['lang']['recover_password_by_sms']?></button>
							</div>
						</div>
					</form>
				<?php } ?>

				<form id="forgot-form" class="small-padd recover_password_by_email" method="post" <?php if( $allow_switch ){ echo 'style="display: none;"'; } ?>>
					<div class="errors"></div>
					<div class="loading_cont">
						<div class="loading hidden"></div>
					</div>
					<div class="sun_input_holder">
						<div class="sun_input">
							<input name="recoveremail" type="email" id="recoveremail" placeholder="<?php echo $wo['lang']['email'];?>" autofocus />
							<label for="recoveremail"><?php echo $wo['lang']['email']?></label>
							<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path><polyline points="22,6 12,13 2,6"></polyline></svg>
						</div>
					</div>
					<?php if($wo['config']['reCaptcha'] == 1) {?>
						<div class="form-group" style="margin-top:10px;">
							<div class="g-recaptcha" data-sitekey="<?php echo $wo['config']['reCaptchaKey']?>"></div>
						</div>
					<?php } ?>
					<div class="login_signup_combo">
						<div class="login__">
							<button type="submit" class="btn btn-main"><?php echo $wo['lang']['recover_password']?></button>
						</div>
						<div class="signup__">
							<a class="dec btn btn-default" href="<?php echo $wo['config']['site_url'];?>"><?php echo $wo['lang']['login']?></a>
						</div>
					</div>
				</form>

				<form id="forgot-form-sms" class="fadeInUp animated animated_9 recover_password_by_sms" method="post" style="display: none;">
					<div class="errors"></div>
					<div class="loading_cont">
						<div class="loading hidden"></div>
					</div>
					<div class="sun_input_holder">
						<div class="sun_input">
							<input name="recoverphone" type="text" id="recoverphone" placeholder="<?php echo $wo['lang']['phone_number'];?>" autofocus />
							<label for="recoverphone"><?php echo $wo['lang']['phone_number']?></label>
							<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"></path></svg>
						</div>
					</div>
					<div class="login_signup_combo">
						<div class="login__">
							<button type="submit" class="btn btn-main"><?php echo $wo['lang']['recover_password']?></button>
						</div>
						<div class="signup__">
							<a class="dec btn btn-default" href="<?php echo $wo['config']['site_url'];?>"><?php echo $wo['lang']['login']?></a>
						</div>
					</div>
				</form>
			</div>
			<div class="col-md-4"></div>
		</div>
	</div>
</div>
<div class="container"><?php echo Wo_LoadPage('footer/welcome');?></div>

<script>
var working = false;
var $this = $('#forgot-form');
var $this_sms = $('#forgot-form-sms');
var $state = $this.find('.errors');
var $state_sms = $this_sms.find('.errors');
$(function() {
	$('#recover_password_by_email').click(function(){
		$('.x_chooser').hide();
		$('.recover_password_by_email').show();
	});
	$('#recover_password_by_sms').click(function(){
		$('.x_chooser').hide();
		$('.recover_password_by_sms').show();
	});

  Wo_SetTimer();
  $this.ajaxForm({
    url: Wo_Ajax_Requests_File() + '?f=recover',
    beforeSend: function() {
		working = true;
		$this.find('button').attr("disabled", true);
		$this.find('.loading').removeClass('hidden');
    },
    success: function(data) {
      if (data.status == 200) {
        $state.addClass('success');
        $state.html('<?php echo $wo['lang']['email_sent'] ?>');
		$this.find('.loading').addClass('hidden');
      } else {
		$this.find('button').attr("disabled", false);
		$this.find('.loading').addClass('hidden');
        $state.html(data.errors);
      }
      working = false;
    }
  });

	$this_sms.ajaxForm({
    url: Wo_Ajax_Requests_File() + '?f=recoversms',
    beforeSend: function() {
		working = true;
		$this_sms.find('button').attr("disabled", true);
		$this_sms.find('.loading').removeClass('hidden');
    },
    success: function(data) {
      if (data.status == 200) {
        $state_sms.addClass('success');
        $state_sms.html('<?php echo $wo['lang']['recoversms_sent'] ?>');
		$this_sms.find('.loading').addClass('hidden');
		setTimeout(function () {
         window.location.href = data.location;
        }, 1000);
      } else {
		$this_sms.find('button').attr("disabled", false);
		$this_sms.find('.loading').addClass('hidden');
        $state_sms.html(data.errors);
      }
      working = false;
    }
  });

});
</script>