(function($) {
	"use strict";

	var ajaxurl = $(
		".elementor-widget-anggita-portfolio-custom .rdn-port-val"
	).data("url");
	var page = 2;
	var portfolio_item = $(
		".elementor-widget-anggita-portfolio-custom .rdn-port-val"
	).data("item");
	var port_column = $(
		".elementor-widget-anggita-portfolio-custom .rdn-port-val"
	).data("col");
	var order_value = $(
		".elementor-widget-anggita-portfolio-custom .rdn-port-val"
	).data("order");
	var security = $(
		".elementor-widget-anggita-portfolio-custom .rdn-port-val"
	).data("nonce");
	var nomore = $(
		".elementor-widget-anggita-portfolio-custom .rdn-port-val"
	).data("nomore");

	$(".elementor-widget-anggita-portfolio-custom .loadmore").on(
		"click",
		function() {
			$(".elementor-widget-anggita-portfolio-custom .loadmore").hide();
			$(".elementor-widget-anggita-portfolio-custom .port-load").show();
			$(".elementor-widget-anggita-portfolio-custom .new-rcol").removeClass(
				"new-rcol"
			);
			var data = {
				action: "load_metro_by_ajax",
				page: page,
				portfolio_item: portfolio_item,
				port_column: port_column,
				order_value: order_value,
				security: security,
				nomore: nomore
			};

			var $grid = $(
				".elementor-widget-anggita-portfolio-custom .c-iso"
			).isotope();

			$.post(ajaxurl, data, function(response) {
				$(".elementor-widget-anggita-portfolio-custom .c-iso").append(response);
				$grid
					.append($(".new-rcol"))
					// add and lay out newly appended elements
					.isotope("appended", $(".new-rcol"), {
						itemSelector: ".port-item",
						layoutMode: "masonry",
						masonry: {
							columnWidth: ".port-item.col-md-3"
						}
					});
				$(".elementor-widget-anggita-portfolio-custom .new-rcol").removeClass(
					"new-rcol"
				);
				page++;
				$(".elementor-widget-anggita-portfolio-custom .port-load").fadeOut(
					"fast"
				);
				setTimeout(function() {
					$(".elementor-widget-anggita-portfolio-custom .loadmore").fadeIn();
				}, 400);
				if (
					$(".elementor-widget-anggita-portfolio-custom .c-iso").find(
						".no-more"
					).length > 0
				) {
					$(".elementor-widget-anggita-portfolio-custom .load-more").remove();
					$(".elementor-widget-anggita-portfolio-custom .box-load").slideUp(
						"fast"
					);
					setTimeout(function() {
						$(".elementor-widget-anggita-portfolio-custom .npsp").fadeOut();
						$(".elementor-widget-anggita-portfolio-custom .npsp").remove();
						$(".portfolio-custom-type").isotope("layout");
					}, 2000);
				}
			});
		}
	);
})(jQuery);
