import Buttons from "./buttons";

(function () {
    const Events = {

        get isPro(){
            return ssgsw_script.is_license_valid
        },
        get isMultiVendor(){
            return ssgsw_script.another_license
        },
        init() {
            new Buttons();
            Events.bindEvents();  
        },

        bindEvents: () => {
            // Show promo
            const promo_buttons = document.querySelectorAll(".ssgsw-promo");
            if (promo_buttons && promo_buttons.length) {
                promo_buttons.forEach(
                    (button) => {
                    button.addEventListener("click", Events.displayPromo);
                    }
                );
            }

            // Sync on google sheet
            const sync_buttons = document.querySelectorAll(".sync-button");
            if (sync_buttons && sync_buttons.length) {
                sync_buttons.forEach(
                    (button) => {
                    button.addEventListener("click", Events.syncOnGoogleSheet);
                    }
                );
            }
            const sync_buttons2 = document.querySelectorAll(".ssgsw_pro_option");
            if (sync_buttons2 && sync_buttons2.length) {
                sync_buttons2.forEach(
                    (button) => {
                    button.addEventListener("click", Events.syncOnGoogleSheet);
                    }
                );
            }

        },

        /**
         * Displays the promo popup
       *
         * @param   {Event} e 
         * @returns 
         */
        displayPromo(e) {
 
            // if (Events.isPro || Events.isMultiVendor ) {
            //     return;
            // }

            e.preventDefault();
      

            WPPOOL.Popup('stock_sync_with_google_sheet_for_woocommerce').show();
        }, 


 
    };

    document.addEventListener("DOMContentLoaded", Events.init);
})();
