(function ($) {
    'use strict';

    var SifencyAccordionHandler = function ($scope, $) {

        var $wrapper = $scope.find('.sifency-advanced-accordion-wrapper');

        if (!$wrapper.length) {
            return;
        }

        $wrapper.find('.sifency-accordion-header').off('click').on('click', function () {

            var $item = $(this).closest('.sifency-accordion-item');
            var $content = $item.find('.sifency-accordion-content');

            if ($item.hasClass('active')) {

                $item.removeClass('active');
                $content.slideUp(300);

            } else {

                $wrapper.find('.sifency-accordion-item.active')
                    .removeClass('active')
                    .find('.sifency-accordion-content')
                    .slideUp(300);

                $item.addClass('active');
                $content.slideDown(300);
            }
        });
    };

    $(window).on('elementor/frontend/init', function () {
        elementorFrontend.hooks.addAction(
            'frontend/element_ready/sifency-addons-accordion.default',
            SifencyAccordionHandler
        );
    });

})(jQuery);
