const ordersLogin = {
  data() {
    return {
      registerMail:'',
      email:'',
      pass:'',
      loginError:''
    }
  },
  mounted() {
  },
  methods: {
    login() {
      const form = {
        "username": this.email,
        "password": this.pass,
        "action":'business_login_function',
        "nonce": myvars.nonce
      }
      request(myvars.ajaxurl, 'post', form, 'json')
      .then(result => {
        this.loginError='';
        if (!result.errors)
          location.href=myvars.reseller
        else
          this.loginError='Credentials not valid'
      })
      
    },
    requestPassword() {
    }
  }
};
Vue.createApp(ordersLogin).mount('#orders-login');
async function request(url, method, data, dataType) {
  let request = jQuery.ajax(
    {
      url:url,
      method:method,
      data:data,
      dataType:dataType
    }
  );
  return request;
}
function login_area_riservata(username, password) {
  //console.log(username, password)
}
// md 
const register_architect = {
  data() {
    return {
      theFormData: {
        email: '',
        password:'',
        name:'',
        surname:'',
        typology:'',
        country:'',
        region:'',
        cap:'',
        city:'',
        phone:'',
        company:'',
        privacy:'',
        marketing:'',
        action:"custom_architect_registration_relaxsrl",
        nonce:myvars.nonce
      },
      has_number:false,
      has_lowercase:false,
      has_uppercase:false,
      has_special:false,
      min_char:false,
      password_length: 0,
      strenght:'',
      canSend:false,
      message : {
        error:true,
        type:false
      }
    }
  },
  mounted() { 
  },
  beforeMount() {
      return {  
        message : {
          error:true,
          type:false
        }
     }
  },
  watch: {
    canSend:function(value) {
      //console.log(this.canSend); 
    }
  },
  methods: {
    register_new_architect_relaxsrl() { 
    
      if (this.canSend) { 
        var mailFormat = $('#f-email').val();    
        if (mailFormat !=''){
            if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mailFormat))  { 
                $('#span-email-msg').css('display','none');
            } else { 
                $('#span-email-msg').css('display','block');
                return false;
            } 
        } 
     
        $(".lds-ring").css("visibility","visible"); 

        request(myvars.ajaxurl, 'post', this.theFormData, 'json')
        .then(result => {
         //console.log(result)
          if (result && result.error == false && result.message == 'sent'){
            $(".q-err").css("display","none");  
            $('body>.ui-tooltip').remove();
            this.message = {
              error:false,
              type:'sent'
            }
          } 
          else {
            const errors = JSON.parse(result.message);
            if (errors.errors.existing_user_login) {
              this.message = {
                error:true,
                type:'duplicated'
              } 
              $("#user-err,.q-err").css("display","block");  
              $("#pwd-err").css("display","none");  
              $(".lds-ring").css("visibility","hidden"); 
              return false;
            }
            
          }
        })
      } else { 
        this.message = {
          error:true,
          type: 'easy_password'
        }
        //console.log(" return false 1 ")
        $("#user-err").css("display","none"); 
        $("#pwd-err").css("display","block"); 
        return false;
      }
    },
    password_check() {
      this.strenght = 'very_low'; 
      const has_number    = /\d/.test(this.theFormData.password);
      const has_lowercase = /[a-z]/.test(this.theFormData.password);
      const has_uppercase = /[A-Z]/.test(this.theFormData.password);
      const has_special   = /[!@#\$%\^\&*\)\(+=._-]/.test(this.theFormData.password);
      const min_char = this.theFormData.password.length > 7;
      const lowercase_length = (this.theFormData.password.match(/[a-z]/g) || []).length;
      const uppercase_length = (this.theFormData.password.match(/[A-Z]/g) || []).length;
      const number_length = (this.theFormData.password.match(/\d/g) || []).length;
      const special_length = (this.theFormData.password.match(/[!@#\$%\^\&*\)\(+=._-]/g) || []).length;
      if (min_char && has_lowercase && has_number)
        this.strenght = 'low';
      if (min_char && has_lowercase && has_uppercase && has_number && has_special)
        this.strenght = 'medium';
      if (min_char && has_lowercase && has_uppercase && has_number && has_special && lowercase_length > 1 && uppercase_length > 1 && number_length > 1 && special_length > 1)
        this.strenght = 'strong';

   

      if (this.strenght != 'low' && this.strenght != 'very_low') {        
        this.canSend = true;        
       // $("#pwd-err").css("display","none");  
      }
      else{
        this.canSend = false;  
       // $("#pwd-err").css("display","block");  
      }
    }
  }
}


Vue.createApp(register_architect).mount('#registration-architect');
