<div class="row small-space-xs hidden" id="container-forgotten">
  <div class="col-xs-12">
    <span class="text-small visible-block"><?php echo $text_recover_password_subtitle; ?></span>
    <form id="form-forgotten" action="<?php echo $action; ?>" method="POST" enctype="multipart/form-data" name="formforgotten">
      <label class="field field-medium top-margin-x-large bottom-margin-medium">
        <input type="text" id="email-forgotten" name="email_forgotten" placeholder="<?php echo $entry_email_placeholder; ?>" class="field-entry validaemail">
      </label>
      <div class="row no-space-xs middle-xs">
        <div class="col-xs">
          <a href="#" class="link-default text-medium text-decoration-none" id="link-login">
            <i class="fas fa-angle-left" aria-hidden="true"></i>
            <span><?php echo $text_back_to_login; ?></span>
          </a>
        </div>
        <div class="col-xs text-right">
          <button type="submit" class="btn-default btn-medium" id="btn-forgotten">
            <span><?php echo $text_send; ?></span>
          </button>
        </div>
      </div>
    </form>
  </div>
</div>

<script>
window.waitEvent('scripts_document', function() {
  $('#form-forgotten').on('submit', function(event) {
    event.preventDefault();
    $('#btn-forgotten').addClass('btn-loading').attr('disabled', 'true');
    
    $.ajax({
      url: $(this).attr('action'),
      type: $(this).attr('method'),
      dataType: 'json',
      data: $(this).serializeObject(),
    })
    .done(function(json) {
      // console.log("success");
      if (json['error_warning']) {
        notificationMsg(json['error_warning'],'warning');
      }
      if (json['success']) {
        notificationMsg(json['success'],'success');
        $('#email-login').val($('#email-forgotten').val());
        $('#password-login').val('');
        $('#container-forgotten, .js-title-forgotten').addClass('hidden').removeAttr('style');
        $('#container-login, .js-title-login').removeClass('hidden').removeAttr('style');
      }
      $('#btn-forgotten').removeClass('btn-loading').removeAttr('disabled');
    })
    .fail(function(json) {
      // console.log("error");
    })
    .always(function(json) {
      // console.log('complete');
      // console.log(json);
    });
  });
});
</script>
