(function ($) {
	/**
	 * @param $scope The Widget wrapper element as a jQuery element
	 * @param $ The jQuery alias
	 */
	var PostTypesSlider = function ($scope, $) {
		(function () {
			if (!$.fn.slick) {
				return;
			}

			var $slideshow = $scope.find('.is-style-ci-theme-layout-overlay-slideshow .row-items, .is-style-ci-theme-post-types-slideshow .row-items');

			if ($slideshow.length !== 0) {
				var columnsClass = $slideshow.attr('class').split(' ').find(function (className) {
					return className.includes('row-columns-');
				}) || '';
				var slidesNo = Number(columnsClass.split('-').pop());

				$slideshow.slick({
					dots: false,
					slidesToShow: slidesNo || 3,
					slidesToScroll: slidesNo || 3,
					prevArrow: '<button type="button" class="slick-prev"><span class="ignition-icons ignition-icons-angle-left"></span></button>',
					nextArrow: '<button type="button" class="slick-next"><span class="ignition-icons ignition-icons-angle-right"></span></i></button>',
					responsive: [
						{
							breakpoint: 1200,
							settings: {
								slidesToShow: 4 === slidesNo || 3,
								slidesToScroll: 4 === slidesNo || 3,
							},
						},
						{
							breakpoint: 992,
							settings: {
								slidesToShow: 1 === slidesNo || 2,
								slidesToScroll: 1 === slidesNo || 2,
							},
						},
						{
							breakpoint: 768,
							settings: {
								slidesToShow: 1,
								slidesToScroll: 1,
							},
						},
					],
				});
			}

		})();
	};

	$(window).on('elementor/frontend/init', function () {
		elementorFrontend.hooks.addAction('frontend/element_ready/ci_post_types.default', PostTypesSlider);
	});
})(jQuery);
