/*
 * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
/******/ (function() { // webpackBootstrap
/******/ 	var __webpack_modules__ = ({

/***/ "./js/src/plugin_settings.js":
/*!***********************************!*\
  !*** ./js/src/plugin_settings.js ***!
  \***********************************/
/***/ (function() {

eval("/* global jQuery, gform, grecaptcha, gforms_recaptcha_recaptcha_strings */\n(function ($) {\n  /**\n   * Handles reCAPTCHA v2 plugin settings validation.\n   *\n   * @since 1.0\n   *\n   * @return {void}\n   */\n  var recaptchaV2Settings = function recaptchaV2Settings() {\n    var v2Settings = {};\n    /**\n     * Initialize reCAPTCHA v2 settings.\n     *\n     * @since 1.0\n     *\n     * @return {void}\n     */\n\n    v2Settings.init = function () {\n      v2Settings.cacheElements();\n      v2Settings.addEventListeners();\n    };\n    /**\n     * Cache the fields used by this handler.\n     *\n     * @since 1.0\n     *\n     * @return {void}\n     */\n\n\n    v2Settings.cacheElements = function () {\n      v2Settings.container = $('div[id=\"gform_setting_reset_v2\"]');\n      v2Settings.fields = {\n        siteKey: $('input[name=\"_gform_setting_site_key_v2\"]'),\n        secretKey: $('input[name=\"_gform_setting_secret_key_v2\"]'),\n        reset: $('input[name=\"_gform_setting_reset_v2\"]'),\n        type: $('input[name=\"_gform_setting_type_v2\"]')\n      };\n    };\n    /**\n     * Add event listeners for this handler.\n     *\n     * @since 1.0\n     *\n     * @return {void}\n     */\n\n\n    v2Settings.addEventListeners = function () {\n      v2Settings.fields.siteKey.on('change', window.loadRecaptcha);\n      v2Settings.fields.secretKey.on('change', window.loadRecaptcha);\n      v2Settings.fields.type.on('change', function () {\n        return window.loadRecaptcha();\n      });\n    };\n    /**\n     * Handles showing and hiding the reCAPTCHA itself.\n     *\n     * @since 1.0\n     *\n     * @return {void}\n     */\n\n\n    window.loadRecaptcha = function () {\n      var self = {};\n      /**\n       * Initialize the reCAPTCHA rendering process.\n       *\n       * @since 1.0\n       *\n       * @return {void}\n       */\n\n      self.init = function () {\n        v2Settings.recaptcha = $('#recaptcha');\n        v2Settings.save = $('#gform-settings-save');\n        self.flushExistingState(); // Reset key status.\n        // Note: recaptcha is misspelled here for legacy reasons.\n\n        $('#recpatcha .gform-settings-field__feedback').remove(); // If no public or private key is provided, exit.\n\n        if (!self.canBeDisplayed()) {\n          self.hideRecaptcha();\n          return;\n        }\n\n        v2Settings.save.prop('disabled', true);\n        self.showSelectedRecaptcha();\n      };\n      /**\n       * Renders the v2 reCAPTCHA.\n       *\n       * @since 1.0\n       *\n       * @param {string} typeValue The selected type to render.\n       *\n       * @return {void}\n       */\n\n\n      self.render = function (typeValue) {\n        // Render reCAPTCHA.\n        grecaptcha.render('recaptcha', {\n          sitekey: v2Settings.fields.siteKey.val().trim(),\n          size: typeValue === 'invisible' ? typeValue : '',\n          badge: 'inline',\n          'error-callback': function errorCallback() {},\n          callback: function callback() {\n            return v2Settings.save.prop('disabled', false);\n          }\n        });\n      };\n      /**\n       * Flush the existing state of the reCAPTCHA handler.\n       *\n       * @since 1.0\n       *\n       * @return {void}\n       */\n\n\n      self.flushExistingState = function () {\n        window.___grecaptcha_cfg.clients = {};\n        window.___grecaptcha_cfg.count = 0;\n        v2Settings.recaptcha.html('');\n        v2Settings.fields.reset.val('1');\n      };\n      /**\n       * Determines whether the reCAPTCHA can be shown.\n       *\n       * @since 1.0\n       *\n       * @return {boolean} Whether the reCAPTCHA can be shown.\n       */\n\n\n      self.canBeDisplayed = function () {\n        return v2Settings.fields.siteKey.val() && v2Settings.fields.secretKey.val();\n      };\n      /**\n       * Hides the reCAPTCHA element.\n       *\n       * @since 1.0\n       *\n       * @return {void}\n       */\n\n\n      self.hideRecaptcha = function () {\n        v2Settings.save.prop('disabled', false);\n        v2Settings.container.hide();\n      };\n      /**\n       * Show the selected reCAPTCHA type.\n       *\n       * @since 1.0\n       *\n       * @return {void}\n       */\n\n\n      self.showSelectedRecaptcha = function () {\n        var typeValue = $('input[name=\"_gform_setting_type_v2\"]:checked').val();\n        self.render(typeValue);\n\n        switch (typeValue) {\n          case 'checkbox':\n            $('#gforms_checkbox_recaptcha_message, label[for=\"reset\"]').show();\n            break;\n\n          case 'invisible':\n            $('#gforms_checkbox_recaptcha_message, label[for=\"reset\"]').hide();\n            break;\n\n          default:\n            throw new Error('Unexpected type selected.');\n        }\n\n        v2Settings.container.show();\n\n        if (typeValue === 'invisible') {\n          grecaptcha.execute();\n        }\n      };\n\n      self.init();\n    };\n\n    v2Settings.init();\n  };\n  /**\n   * Handles reCAPTCHA v3 plugin settings validation.\n   *\n   * @since 1.0\n   *\n   * @return {void}\n   */\n\n\n  var recaptchaV3Settings = function recaptchaV3Settings() {\n    var v3Settings = {};\n    /**\n     * Initializes the reCAPTCHA v3 settings handler.\n     *\n     * @since 1.0\n     *\n     * @return {void}\n     */\n\n    v3Settings.init = function () {\n      v3Settings.token = '';\n      v3Settings.strings = gforms_recaptcha_recaptcha_strings;\n      v3Settings.cacheElements();\n      v3Settings.validateKeysV3();\n      v3Settings.addEventListeners();\n    };\n    /**\n     * Cache HTML elements for the v3 reCAPTCHA settings.\n     *\n     * @since 1.0\n     *\n     * @return {void}\n     */\n\n\n    v3Settings.cacheElements = function () {\n      v3Settings.fields = {\n        siteKey: '#site_key_v3',\n        secretKey: '#secret_key_v3',\n        threshold: '#score_threshold_v3',\n        disableBadge: '#disable_badge_v3',\n        keysStatus: '#gform_setting_recaptcha_keys_status_v3'\n      };\n      v3Settings.cache = {\n        siteKey: $(v3Settings.fields.siteKey),\n        secretKey: $(v3Settings.fields.secretKey),\n        keysStatus: $(v3Settings.fields.keysStatus),\n        save: $('#gform-settings-save')\n      };\n    };\n    /**\n     * Setup event listeners for field validation.\n     *\n     * @since 1.0\n     *\n     * @return {void}\n     */\n\n\n    v3Settings.addEventListeners = function () {\n      if (!v3Settings.strings.site_key.length) {\n        return;\n      }\n\n      $(v3Settings.fields.siteKey).on('keyup', function () {\n        return v3Settings.clearValidationFeedback();\n      });\n      $(v3Settings.fields.secretKey).on('keyup', function () {\n        return v3Settings.clearValidationFeedback();\n      });\n    };\n    /**\n     * Empty out the validation feedback if the fields are modified, as we can't yet know the status.\n     *\n     * @since 1.0\n     *\n     * @return {void}\n     */\n\n\n    v3Settings.clearValidationFeedback = function () {\n      v3Settings.unsetValid(v3Settings.cache.siteKey.closest('.gform-settings-input__container'));\n      v3Settings.unsetValid(v3Settings.cache.secretKey.closest('.gform-settings-input__container'));\n    };\n    /**\n     * Handles validation of the v3 site key.\n     *\n     * @since 1.0\n     *\n     * @return {Promise<unknown>} Returns a promise so this can be verified synchronously if checking the secret key.\n     */\n\n\n    v3Settings.getRecaptchaToken = function () {\n      return new Promise(function (resolve, reject) {\n        var siteKeyContainer = v3Settings.cache.siteKey.closest('.gform-settings-input__container');\n\n        try {\n          var siteKey = v3Settings.cache.siteKey;\n          var siteKeyValue = siteKey.val().trim();\n\n          if (0 === siteKeyValue.length) {\n            v3Settings.unsetValid(siteKeyContainer);\n            v3Settings.unsetValid(v3Settings.cache.keysStatus.closest('.gform-settings-input__container'));\n            $(v3Settings.fields.keysStatus).find('input').val('0');\n            return;\n          }\n\n          grecaptcha.ready(function () {\n            try {\n              grecaptcha.execute(siteKeyValue, {\n                action: 'submit'\n              }).then(function (token) {\n                resolve(token);\n              });\n            } catch (error) {\n              reject(error);\n            }\n          });\n        } catch (error) {\n          reject(error);\n        }\n      });\n    };\n    /**\n     * Handles validation of the v3 site and secret keys.\n     *\n     * On page load, attempt to generate a reCAPTCHA token and immediately validate it on the server. If it's good,\n     * we'll update the presentation of the keys to indicate success or failure.\n     *\n     * @since 1.0\n     *\n     * @return {void}\n     */\n\n\n    v3Settings.validateKeysV3 = function () {\n      var siteKeyContainer = v3Settings.cache.siteKey.closest('.gform-settings-input__container');\n      var secretKeyContainer = v3Settings.cache.secretKey.closest('.gform-settings-input__container');\n      var keysStatusInput = $(v3Settings.fields.keysStatus).find('input');\n\n      if (!$(v3Settings.fields.siteKey).val().trim().length) {\n        v3Settings.unsetValid(siteKeyContainer);\n        v3Settings.unsetValid(secretKeyContainer);\n        keysStatusInput.val('0');\n        return;\n      }\n\n      v3Settings.getRecaptchaToken().then(function (token) {\n        v3Settings.token = token;\n      }).catch(function () {\n        v3Settings.setInvalid(siteKeyContainer);\n        v3Settings.setInvalid(secretKeyContainer);\n        keysStatusInput.val('0');\n      }).finally(function () {\n        $.ajax({\n          method: 'POST',\n          dataType: 'JSON',\n          url: v3Settings.strings.ajaxurl,\n          data: {\n            action: 'verify_secret_key',\n            nonce: v3Settings.strings.nonce,\n            token: v3Settings.token,\n            site_key_v3: $(v3Settings.fields.siteKey).val(),\n            secret_key_v3: $(v3Settings.fields.secretKey).val()\n          }\n        }).then(function (response) {\n          switch (response.data.keys_status) {\n            case '1':\n              v3Settings.setValid(siteKeyContainer);\n              v3Settings.setValid(secretKeyContainer);\n              keysStatusInput.val('1');\n              break;\n\n            case '0':\n              v3Settings.setInvalid(siteKeyContainer);\n              v3Settings.setInvalid(secretKeyContainer);\n              keysStatusInput.val('0');\n              break;\n\n            default:\n              v3Settings.unsetValid(siteKeyContainer);\n              v3Settings.unsetValid(secretKeyContainer);\n              keysStatusInput.val('0');\n          }\n        });\n      });\n    };\n    /**\n     * Updates the text field to display no feedback.\n     *\n     * @since 1.0\n     *\n     * @param {Object} el The jQuery element.\n     *\n     * @return {void}\n     */\n\n\n    v3Settings.unsetValid = function (el) {\n      el.removeClass('gform-settings-input__container--feedback-success');\n      el.removeClass('gform-settings-input__container--feedback-error');\n    };\n    /**\n     * Updates the text field to display the successful feedback.\n     *\n     * @since 1.0\n     *\n     * @param {Object} el The jQuery element.\n     *\n     * @return {void}\n     */\n\n\n    v3Settings.setValid = function (el) {\n      el.addClass('gform-settings-input__container--feedback-success');\n      el.removeClass('gform-settings-input__container--feedback-error');\n    };\n    /**\n     * Updates the text field to display the error feedback.\n     *\n     * @since 1.0\n     *\n     * @param {Object} el The jQuery element.\n     *\n     * @return {void}\n     */\n\n\n    v3Settings.setInvalid = function (el) {\n      el.removeClass('gform-settings-input__container--feedback-success');\n      el.addClass('gform-settings-input__container--feedback-error');\n    };\n\n    v3Settings.init();\n  };\n\n  $(document).ready(function () {\n    recaptchaV3Settings();\n    recaptchaV2Settings();\n    gform.adminUtils.handleUnsavedChanges('#gform-settings');\n  });\n})(jQuery);\n\n//# sourceURL=webpack://gravityformsrecaptcha/./js/src/plugin_settings.js?");

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	// This entry module can't be inlined because the eval devtool is used.
/******/ 	var __webpack_exports__ = {};
/******/ 	__webpack_modules__["./js/src/plugin_settings.js"]();
/******/ 	
/******/ })()
;