"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = withRecaptchaProvider;

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _react = require("react");

var _reactGoogleRecaptchaV = require("react-google-recaptcha-v3");

var _client = require("./client.cjs");

var _reactIntl = require("react-intl");

var _jsxRuntime = require("react/jsx-runtime");

function withRecaptchaProvider(Form) {
  return /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
    var externalReCaptchaProviderExists = props.externalReCaptchaProviderExists,
        config = props.config,
        isLastStep = props.isLastStep;

    var _useConfig = (0, _client.useConfig)(),
        recaptcha = _useConfig.recaptcha;

    var intl = (0, _reactIntl.useIntl)();

    if (!externalReCaptchaProviderExists && (config === null || config === void 0 ? void 0 : config.requireCaptcha) && (isLastStep === true || isLastStep === undefined)) {
      var _intl$locale;

      return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactGoogleRecaptchaV.GoogleReCaptchaProvider, {
        reCaptchaKey: recaptcha.sitekey,
        language: (_intl$locale = intl.locale) === null || _intl$locale === void 0 ? void 0 : _intl$locale.split('-')[0],
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Form, (0, _objectSpread2["default"])({
          ref: ref
        }, props))
      });
    } else {
      return /*#__PURE__*/(0, _jsxRuntime.jsx)(Form, (0, _objectSpread2["default"])({
        ref: ref
      }, props));
    }
  });
}
//# sourceMappingURL=withRecaptchaProvider.cjs.map