(function ($) {
    "use strict";

    const initSifencySchema = function ($scope, $) {
        const wrapper = $scope.find(".sifency-howto-wrapper");
        
        if (wrapper.hasClass("sifency-howto-layout-accordion")) {
            const headers = wrapper.find(".sifency-howto-step-header");

            headers.off("click").on("click", function () {
                const step = $(this).parent();
                const content = step.find(".sifency-howto-step-content");
                const icon = $(this).find(".sifency-toggle-icon");
                
                const allSteps = wrapper.find(".sifency-howto-step");
                const allContents = wrapper.find(".sifency-howto-step-content");
                const allIcons = wrapper.find(".sifency-toggle-icon");

                if (!step.hasClass("active")) {
                    allSteps.removeClass("active");
                    allContents.slideUp(300);
                    allIcons.removeClass("eicon-minus").addClass("eicon-plus");

                    step.addClass("active");
                    content.slideDown(300);
                    icon.removeClass("eicon-plus").addClass("eicon-minus");
                } 
                else {
                    step.removeClass("active");
                    content.slideUp(300);
                    icon.removeClass("eicon-minus").addClass("eicon-plus");
                }
            });
        }
    };

    $(window).on("elementor/frontend/init", function () {
        elementorFrontend.hooks.addAction("frontend/element_ready/sifency-schema.default", initSifencySchema);
    });

})(jQuery);