$("#sendPassword").click(function(){

  console.log("hi");
  if(!$("#Mobile").val()){
    $("#Mobile").addClass("border border-danger")
  } else if($("#Mobile").hasClass("wrongInput")){
    $("#Mobile").addClass("border border-danger")
  } else{
    $("#Mobile").removeClass("border border-danger")
    if($('#PrivacyPolicy').is(':checked')){
      var numbers = convertNumbers2English($('input').val());
      console.log("numbers");
      console.log(numbers);

      axios
          .post("/kavenegar/admin/logincode", {
            number : numbers
          })
          .then((res) => {
            loginCode = res.data.loginCode
          })

      $(".form-group > input").attr("readonly", true)
      $("#wrongNumberContainer").removeClass("d-none")
      $(".send").empty()
      $(".send").append('<div class="container"><div class="form-group"><label>کد تایید</label><input name="Password" id="Password" type="text" class="form-control with-light" placeholder="کد تایید" /></div></div><div class="col-lg-12 col-md-12"><div class="form-group"><button type="submit" class="btn btn-success dark-3" id="sendPassword">وارد شدن</button></div></div>')
    } else {
      $('#PrivacyPolicy').addClass("shake-input")
      setTimeout(function () {
        $('#PrivacyPolicy').removeClass("shake-input")
      }, 500);
    }
  }
})
$("#wrongNumber").click(function () {
  console.log("wrongNumber");
  $("#wrongNumberContainer").addClass("d-none")
  $(".form-group > input").attr("readonly", false)
  $(".send").empty()
})


$("#Mobile").on('keyup', function (event) {
  // var arregex = /^09|^۰۹[0-9۰-۹]*$/;
  var enArregex = /^09(1[0-9]|3[1-9]|2[1-9]|9[1-9])-?[0-9]{3}-?[0-9]{4}$/;
  var fnArregex = /^۰۹(۱[۰-۹]|۳[۱-۹]|۲[۱-۹]|۹[۱-۹])-?[۰-۹]{3}-?[۰-۹]{4}$/;
  console.log($(this).val());
  if ($(this).val() == ""){
    console.log("not a number");
    $(this).addClass("wrongInput")
  } else if (!enArregex.test($(this).val()) && !fnArregex.test($(this).val())) {
    console.log("not a number");
    $(this).addClass("wrongInput")
  } else {
    console.log("a number");
    $(this).removeClass("wrongInput")
    $(this).removeClass("border border-danger")
  }
});

function convertNumbers2English(string) {
  return string.replace(/[\u0660-\u0669]/g, function (c) {
    return c.charCodeAt(0) - 0x0660;
  }).replace(/[\u06f0-\u06f9]/g, function (c) {
    return c.charCodeAt(0) - 0x06f0;
  });
}

