/* Essentials YOOtheme Pro 2.2.16 build 0813.1608; ZOOlanders https://www.zoolanders.com; Copyright (C) Joolanders, SL; http://www.gnu.org/licenses/gpl.html GNU/GPL */

import formComponent from './component';
import downloadAction from '../../actions/Download/script.js';
import messageAction from '../../actions/Message/script.js';
import redirectAction from '../../actions/Redirect/script.js';

onDomReady(() => {
    const UIkit = window.UIkit;

    if (!UIkit || !UIkit?.version?.match(/^3\./)) {
        throw new Error('YOOessentials Form Init Error: UIkit v3.x is required.');
    }

    UIkit.component('yooessentials-form', formComponent(UIkit));

    downloadAction(UIkit);
    messageAction(UIkit);
    redirectAction(UIkit);
});

function onDomReady(fn) {
    if (window.document.readyState !== 'loading') {
        fn();
        return;
    }

    window.document.addEventListener(
        'DOMContentLoaded',
        () => {
            fn();
        },
        {
            once: true,
        }
    );
}
