// source --> https://clickregion.org.au/wp-content/plugins/memberpress/js/login.js?ver=1.12.16 
(function($) {
  __ = wp.i18n.__;

  function resetToggle( $button, show ) {
    $button
      .attr({
        'aria-label': show ? __( 'Show password' ) : __( 'Hide password' )
      })
      .find( '.text' )
        .text( show ? __( 'Show' ) : __( 'Hide' ) )
      .end()
      .find( '.dashicons' )
        .removeClass( show ? 'dashicons-hidden' : 'dashicons-visibility' )
        .addClass( show ? 'dashicons-visibility' : 'dashicons-hidden' );
  }

  $(document).ready( function() {
    $('body').on('click', 'button.mp-hide-pw', function () {
      var $button = $(this),
        $pass = $button.siblings('#user_pass');

      // Detect alternative password field if the default one is not found.
      if( ! $pass.length ){
        $pass = $button.parent('div.mp-hide-pw').find('input');
      }

      // Bailout if the password field is not found.
      if( ! $pass.length ){
        return;
      }

      if ( 'password' === $pass.attr( 'type' ) ) {
        $pass.attr( 'type', 'text' );
        resetToggle( $button, false );
      } else {
        $pass.attr( 'type', 'password' );
        resetToggle( $button, true );
      }
    });

    // Pro Template
    if( $('#mepro-login-hero').length ){
      if( $('#mepr_loginform').length ){
        $("#user_login, #user_pass").on("input", function(){
          if ( $('#user_login').val().length > 0 && $('#user_pass').val().length > 0) {
            $('#wp-submit').removeClass('disabled');
          }
        })
      }
    }

    // Handle form labels
    const $usernameInput = $('#user_login');
    const $passwordInput = $('#user_pass');
    const $usernameLabel = $usernameInput.closest('.mp-form-row').find('label');
    const $passwordLabel = $passwordInput.closest('.mp-form-row').find('label');

    handleFormLabels(null, $usernameInput, $usernameLabel);
    handleFormLabels(null, $passwordInput, $passwordLabel);

    $usernameInput.on('keyup', function(event) {
      handleFormLabels(event, $usernameInput, $usernameLabel);
    });
    $passwordInput.on('keyup', function(event) {
      handleFormLabels(event, $passwordInput, $passwordLabel);
    });

    function handleFormLabels(event, input, label) {
      if (input.val() === '') {
        label.removeClass('active');
      } else {
        label.addClass('active');
      }
    }
    // End Pro Template
  });
})(jQuery);
// source --> https://clickregion.org.au/wp-content/plugins/memberpress/js/account.js?ver=1.12.16 
jQuery(document).ready(function ($) {
  const body = $('body');

  $('.mepr-open-resume-confirm, .mepr-open-cancel-confirm').magnificPopup({
    type: 'inline',
    closeBtnInside: false
  });

  body.on('click', '.mepr-confirm-no', function() {
    $.magnificPopup.close();
  });

  body.on('click', '.mepr-confirm-yes', function(){
    location.href = $(this).data('url');
  });

  $('.mepr-open-upgrade-popup').magnificPopup({
    type: 'inline',
    closeBtnInside: false
  });

  body.on('click', '.mepr-upgrade-cancel', function() {
    $.magnificPopup.close();
  });

  body.on('click', '.mepr-upgrade-buy-now', function(){
    var id = $(this).data('id');
    var selector = 'select#mepr-upgrade-dropdown-' + id;
    location.href = $(selector).val();
  });

  var meprValidateAccountInput = function (obj) {
    $(obj).removeClass('invalid');

    if ($(obj).attr('required') !== undefined) {
      var notBlank = mpValidateFieldNotBlank($(obj));
      mpToggleFieldValidation($(obj), notBlank);
    }

    // Validate actual email only if it's not empty otherwise let the required/un-required logic hold
    if ($(obj).attr('type')==='email' && $(obj).val().length > 0) {
      var validEmail = mpValidateEmail($(obj).val());
      mpToggleFieldValidation($(obj), validEmail);
    }
  };

  body.on('click', '.mepr-account-form .mepr-submit', function (e) {
    e.preventDefault();
    var form = $(this).closest('.mepr-account-form');
    var submittedTelInputs = document.querySelectorAll(".mepr-tel-input");
    for (var i = 0; i < submittedTelInputs.length; i++) {
      var iti = window.intlTelInputGlobals.getInstance(submittedTelInputs[i]);
      submittedTelInputs[i].value = iti.getNumber();
    }

    // Loop through each field and validate if it's required.
    $.each(form.find('.mepr-form-input:visible'), function(i,obj) {
      meprValidateAccountInput(obj);
    });

    // Validation failed? Bailout.
    if (0 < form.find('.invalid').length) {
      return;
    }

    form.submit();
  });

});