'use client'
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var jsxRuntime = require('react/jsx-runtime');
var HCaptcha = require('@hcaptcha/react-hcaptcha');
var reactTurnstile = require('@marsidev/react-turnstile');
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
require('../../context/DynamicContext/useDynamicContext/useDynamicContext.cjs');
var useInternalDynamicContext = require('../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
var captcha = require('../../utils/captcha.cjs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var HCaptcha__default = /*#__PURE__*/_interopDefaultLegacy(HCaptcha);

const Captcha = ({ handleSuccess }) => {
    const { projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
    const captchaConfig = captcha.getActiveCaptchaConfig(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.security);
    if (!captchaConfig)
        return null;
    const theme = document.body.dataset.dynamicTheme === 'dark' ? 'dark' : 'light';
    if (captchaConfig.provider === sdkApiCore.CaptchaProviderEnum.CloudflareTurnstile) {
        return (jsxRuntime.jsx(reactTurnstile.Turnstile, { siteKey: captchaConfig.siteKey, onSuccess: handleSuccess, options: { theme } }));
    }
    return (jsxRuntime.jsx("form", { "data-testid": 'captcha-form', children: jsxRuntime.jsx(HCaptcha__default["default"], { sitekey: captchaConfig.siteKey, onVerify: (token) => handleSuccess(token), theme: theme }) }));
};

exports.Captcha = Captcha;
