"use strict";

/**
 * @class Cibertest
 * @constructor
 * @returns {void}
 * @access public
 * @static
 */
const Cibertest = (function(){

    /**
     * @callback cookies_click_callback
     * @returns {void}
     */

    /** 
     * @constructs Cibertest
     * @returns {void}
     * @access private
     * @static
     */
    const Cibertest = function(){};

    /**
     * @returns {void}
     * @access public
     * @static
     */
    Cibertest.cookies_reject = () => {
        if(!document.querySelector(".fc-dialog-container"))
            return;

        /**
         * @returns {void}
         */
        const reject_all = () => {
            document.querySelectorAll(".fc-dialog-container [type=checkbox]:checked").forEach(checkbox => {
                checkbox.checked = false;
            });
        };

        /**
         * @param {?string} selector 
         * @param {?cookies_click_callback} [callback = null] 
         * @returns {boolean}
         */
        const click = (selector, callback = null) => {

            /** @type {boolean} */
            let ok = !selector;

            if(!ok){

                /** @type {HTMLElement} */
                const button = document.querySelector(selector);

                if(button){
                    button.click();
                    ok = true;
                };

            };

            ok && callback && callback();

            return ok;
        };

        reject_all();
        ["fc-cta-manage-options", "fc-manage-vendors"].forEach(selector => {
            click(".fc-dialog-container ." + selector, reject_all);
        });
        click(".fc-dialog-container button.fc-confirm-choices");

    };

    /**
     * @returns {void}
     * @access public
     * @static
     */
    Cibertest.load_test = () => {
        Cibertest.reject_cookies();
    };

    return Cibertest;
})();

Cibertest.load_test();