$(document).ready(() => {
  const new_account = $("input[name='new_account']");
  const preview_icon = $("#preview-icon");
  console.log(preview_icon);

  new_account.on("keyup", () => {
    // console.log("keyup is called");
    const visa = new RegExp(/^4[0-9]{1,12}((?:[0-9]{1,3}))?$/);
    const mastercard = new RegExp(/^5[1-5]{1}[0-9]{0,14}$/);
    const amex = new RegExp(/^3[47]{2}[0-9]{0,13}$/);
    const amex2 = new RegExp(/^3[76]{2}[0-9]{0,13}$/);
    const amex3 = new RegExp(/^3[74]{2}[0-9]{0,13}$/);
    // const discover = new RegExp(/^6(?:011|5[0-9]{2})[0-9]{0,12}$/);
    const jcb = new RegExp(/^35[0-9]{0,14}$/);
    if (visa.test(new_account.val())) {
      preview_icon.attr("src", "/ANTICODE/Anticode/img/client/visa.png");
      $("#cid-container").addClass("hide");
    } else if (mastercard.test(new_account.val())) {
      preview_icon.attr(
        "src",
        "/ANTICODE/Anticode/img/client/mastercard_kecil.png"
      );
      $("#cid-container").addClass("hide");
    } else if (
      amex.test(new_account.val()) ||
      amex2.test(new_account.val()) ||
      amex3.test(new_account.val())
    ) {
      preview_icon.attr(
        "src",
        "/ANTICODE/Anticode/img/client/amexrican_kecil.png"
      );
      $("#cid-container").removeClass("hide");
      //   preview_icon.attr("width", "45");
    } else if (jcb.test(new_account.val())) {
      preview_icon.attr("src", "/ANTICODE/Anticode/img/client/jcb_kecil.png");
      $("#cid-container").addClass("hide");
    } else {
      preview_icon.attr("src", "/ANTICODE/Anticode/img/client/cc_kecil.png");
      $("#cid-container").addClass("hide");
    }
  });
});

// document.querySelectorAll;
