import { loadESModule } from '../../core/src/utils/loadESModule.mjs';

const loadRecaptchaClient = (siteKey)=>loadESModule(`https://www.google.com/recaptcha/enterprise.js?render=${siteKey}`, ()=>window.grecaptcha.enterprise);
class CaptchaProvider {
    bootstrapPromise;
    state;
    constructor(bootstrapPromise){
        this.bootstrapPromise = bootstrapPromise;
        this.state = bootstrapPromise.then(async (bootstrapData)=>{
            if (!bootstrapData.captchaSettings.enabled) {
                return {
                    configured: false
                };
            }
            return {
                configured: true,
                captchaClient: await loadRecaptchaClient(bootstrapData.captchaSettings.siteKey),
                siteKey: bootstrapData.captchaSettings.siteKey
            };
        });
    }
    executeRecaptcha = async ()=>{
        const { captchaClient, configured, siteKey } = await this.state;
        if (!configured) {
            return undefined;
        }
        await new Promise((resolve)=>captchaClient.ready(resolve));
        return captchaClient.execute(siteKey, {
            action: 'LOGIN'
        });
    };
}

export { CaptchaProvider };
//# sourceMappingURL=CaptchaProvider.mjs.map
