'use client'
import { jsx } from 'react/jsx-runtime';
import HCaptcha from '@hcaptcha/react-hcaptcha';
import { Turnstile } from '@marsidev/react-turnstile';
import { CaptchaProviderEnum } from '@dynamic-labs/sdk-api-core';
import '../../context/DynamicContext/useDynamicContext/useDynamicContext.js';
import { useInternalDynamicContext } from '../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
import { getActiveCaptchaConfig } from '../../utils/captcha.js';

const Captcha = ({ handleSuccess }) => {
    const { projectSettings } = useInternalDynamicContext();
    const captchaConfig = 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 === CaptchaProviderEnum.CloudflareTurnstile) {
        return (jsx(Turnstile, { siteKey: captchaConfig.siteKey, onSuccess: handleSuccess, options: { theme } }));
    }
    return (jsx("form", { "data-testid": 'captcha-form', children: jsx(HCaptcha, { sitekey: captchaConfig.siteKey, onVerify: (token) => handleSuccess(token), theme: theme }) }));
};

export { Captcha };
