import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import { forwardRef } from "react";
import { GoogleReCaptchaProvider } from "react-google-recaptcha-v3";
import { useConfig } from "./client.js";
import { useIntl } from "react-intl";
import { jsx as _jsx } from "react/jsx-runtime";
export default function withRecaptchaProvider(Form) {
  return /*#__PURE__*/forwardRef(function (props, ref) {
    var externalReCaptchaProviderExists = props.externalReCaptchaProviderExists,
        config = props.config,
        isLastStep = props.isLastStep;

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

    var intl = useIntl();

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

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