(function($) {
    const initParticles = function($scope) {
        const $el = $scope.find('.okt-particles-wrapper');
        if (!$el.length) return;

        const id     = $el.attr('id');
        const config = $el.data('config'); // jQuery auto-parses JSON from data attributes

        if (!id || !config || typeof particlesJS === 'undefined') return;

        particlesJS(id, config);
    };

    $(window).on('elementor/frontend/init', function() {
        elementorFrontend.hooks.addAction('frontend/element_ready/okthemes-particles.default', initParticles);
    });
})(jQuery);
