/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
export const setupRecaptcha = (recaptchaKey, language = 'en', callback = () => { }) => {
    console.log(language);
    if (!recaptchaKey)
        return;
    const oldScript = document.querySelector("script[src*='recaptcha/api.js']");
    if (oldScript) {
        oldScript.remove();
        console.log('Old reCAPTCHA script removed');
    }
    const recaptchaContainers = document.getElementsByClassName('g-recaptcha');
    Array.from(recaptchaContainers).forEach(container => container.remove());
    const script = document.createElement('script');
    script.src = `https://www.google.com/recaptcha/api.js?render=explicit&hl=${language}`;
    script.async = true;
    script.defer = true;
    script.onload = () => {
        console.log(`reCAPTCHA script loaded with language: ${language}`);
        callback();
    };
    document.head.appendChild(script);
};
