jQuery(function ($) {
  "use strict";

  const ANET_ENVIRONMENT_TEST = ANET_ENV_TEST;

  // Credit Card Environment Toggle
  function toggleCreditCardEnvFields() {
    var env = $("#woocommerce_anet_testmode").val();
    $(".environment-field.anet-field").closest("tr").hide();
    if (ANET_ENVIRONMENT_TEST === env) {
      $(".test-field.anet-field").closest("tr").show();
    } else {
      $(".production-field.anet-field").closest("tr").show();
    }
  }
  $("#woocommerce_anet_testmode").on("change", toggleCreditCardEnvFields);
  toggleCreditCardEnvFields();

  // eCheck Environment Toggle
  function toggleEcheckEnvFields() {
    var env = $("#woocommerce_anet_echeck_testmode").val();
    $(".environment-field.anet_echeck-field").closest("tr").hide();
    if (ANET_ENVIRONMENT_TEST === env) {
      $(".test-field.anet_echeck-field").closest("tr").show();
    } else {
      $(".production-field.anet_echeck-field").closest("tr").show();
    }
  }
  $("#woocommerce_anet_echeck_testmode").on("change", toggleEcheckEnvFields);
  toggleEcheckEnvFields();
});
