"use strict";
gsap.registerPlugin(ScrollTrigger, SplitText, ScrollSmoother);
gsap.config({
	nullTargetWarn: false,
	trialWarn: false
});
/*----  Functions  ----*/
function pbmit_img_animation() {
	const boxes = gsap.utils.toArray('.pbmit-animation-style1,.pbmit-animation-style2,.pbmit-animation-style3,.pbmit-animation-style4,.pbmit-animation-style5,.pbmit-animation-style6,.pbmit-animation-style7');
	boxes.forEach(img => {
		gsap.to(img, {
			scrollTrigger: {
				trigger: img,
				start: "top 70%",
				end: "bottom bottom",
				toggleClass: "active",
				once: true,
			}
		});
	});
}
function getpercentage(x, y, elm) {
	elm.find('.pbmit-fid-inner').html(y + '/' + x);
	var cal = Math.round((y * 100) / x);
	return cal;
}
function pbmit_title_animation() {
	ScrollTrigger.matchMedia({
		"(min-width: 1025px)": function() {
			var pbmit_var = jQuery('.pbmit-custom-heading, .pbmit-heading-subheading');
			if (!pbmit_var.length) {
				return;
			}
			const quotes = document.querySelectorAll(".pbmit-custom-heading .pbmit-element-title , .pbmit-heading-subheading .pbmit-element-title");
			quotes.forEach(quote => {
				var getclass = quote.closest('.pbmit-custom-heading ,.pbmit-heading-subheading').className;
				var animation = getclass.split('animation-');
				if (animation[1] == "style4") return
				//Reset if needed
				if (quote.animation) {
					quote.animation.progress(1).kill();
					quote.split.revert();
				}
				quote.split = new SplitText(quote, {
					type: "lines,words,chars",
					linesClass: "split-line"
				});
				gsap.set(quote, { perspective: 400 });
				if (animation[1] == "style1") {
					gsap.set(quote.split.chars, {
						opacity: 0,
						y: "90%",
						rotateX: "-40deg"
					});
				}
				if (animation[1] == "style2") {
					gsap.set(quote.split.chars, {
						opacity: 0,
						x: "50"
					});
				}
				if (animation[1] == "style3") {
					gsap.set(quote.split.chars, {
						opacity: 0,
					});
				}
				quote.animation = gsap.to(quote.split.chars, {
				scrollTrigger: {
					trigger: quote,
					start: "top 90%",
				},
				x: "0",
				y: "0",
				rotateX: "0",
				opacity: 1,
				duration: 1,
				ease: Back.easeOut,
				stagger: .02
				});
			});
		},
	});
}
function pbmit_sticky() {
	ScrollTrigger.matchMedia({
		"(min-width: 1200px)": function() {
			let pbmit_sticky_container = jQuery(".pbmit-sticky-col");
			let section = pbmit_sticky_container.closest('.elementor-section');
			if (!section[0]) {
				section = pbmit_sticky_container.closest('.pbmit-sticky-section');
			} 
			let tl = gsap.timeline({
				scrollTrigger: {
					pin: pbmit_sticky_container,
					scrub: 1,
					start: "top top", 
					trigger: section,
					end: () => "+=" + ((section.height() + 300) - window.innerHeight), 
					invalidateOnRefresh: true
				},
				defaults: { ease: "none", duration: 1 }
			});
		},
	}); 
}
function pbmit_set_tooltip() {
	jQuery('[data-cursor-tooltip]').each(function() {
		var thisele = jQuery(this);
		var thisele_html = thisele.find('.pbminfotech-box-content').html();
		thisele.attr("data-cursor-tooltip", thisele_html);
	});
}
function pbmit_squire_image() {
	const pbmit_elm = gsap.utils.toArray('.pbmit-textimonial-bg-move');
	if (pbmit_elm.length == 0) return
	ScrollTrigger.matchMedia({
		"(min-width: 992px)": function() {
			pbmit_elm.forEach((box, i) => {
				let tl = gsap.timeline({
					scrollTrigger: {
						trigger: box,
						start: "top 80%",
						end: "+=700px",
						scrub: 1
					},
					defaults: { ease: "none" }
				});
				tl.fromTo(box, { clipPath: 'inset(0% 7% 0% 7%)' }, { clipPath: 'inset(0% 0% 0% 0%)', duration: 3 }) 
			});
		}
	});
}
function pbmit_extend_section() {
	const pbmit_elm = gsap.utils.toArray('.pbmit-extend-animation');
	if (pbmit_elm.length == 0) return	
	ScrollTrigger.matchMedia({
		"(min-width: 1200px)": function() {
			pbmit_elm.forEach(section => {
				let tl = gsap.timeline({
					scrollTrigger: {
						trigger: section,
						start: "top 50%",
						end: "+=400px",
						scrub: 1
					},
					defaults: { ease: "none" }
				});
				tl.fromTo(section, { clipPath: 'inset(0% 5% 0% 5% round 30px)' }, { clipPath: 'inset(0% 0% 0% 0% round 30px)', duration: 1.5 })	
			});			 
		},
		"(max-width:1200px)": function() {
			ScrollTrigger.getAll().forEach(section => section.kill(true));
		}
	});
}
function pbmit_portfolio4_slider() {
	jQuery(".pbmit-element-portfolio-style-4").each(function() {
		if (typeof Swiper !== 'undefined') {
			var pbmit_port_slide = new Swiper('.swiper-hover-slide-nav', {
				spaceBetween: 0,
				autoplay :false,
				loop:true,
				slidesPerView: '1',
				navigation: {
					nextEl: '.swiper-button-next',
					prevEl: '.swiper-button-prev',
				},
				breakpoints	: {
					1025: {
						slidesPerView: '4',
					},
					767: {
						slidesPerView: '3',
					},
					575: {
						slidesPerView: '2',
					},
				},
			});
			var pbmit_hover_fade1 = new Swiper(".pbmit-hover-image-faded", {
				speed: 6000,
				effect: 'fade',
			});
			jQuery('.pbmit-main-hover-faded .swiper-hover-slide-nav .swiper-slide').on('mouseover',function(e) {
				e.preventDefault();
				var myindex = jQuery(this).attr('data-swiper-slide-index');
				pbmit_hover_fade1.slideTo(myindex, 2000, false);
			});
		}
	});		
}
function pbmit_animate_custom_text() {
	jQuery("#js-rotating").Morphext({
		animation: "flipInX",
		speed: 3000,
	});
}
function pbmit_ihbox_move() {
	var pbmit_var = jQuery('.pbmit-move-sofa');
	if (!pbmit_var.length) {
		return;
	}
	ScrollTrigger.matchMedia({
		"(min-width: 1200px)": function() {
			gsap.set(".pbmit-move-sofa", { yPercent:20, })
			gsap.to(".pbmit-move-sofa", {		
				yPercent: -50,
				scrollTrigger: {
					scrub: true,
					start: () => "top top", 
					end:() =>  "bottom top",
					scrub:2
				}
			});
		},
		"(max-width:1200px)": function() {
			ScrollTrigger.getAll().forEach(scrub => scrub.kill(true));
		}
	});
}
ScrollTrigger.addEventListener("refresh", pbmit_title_animation);
ScrollTrigger.matchMedia({
	"(max-width: 1200px)": function() {
		ScrollTrigger.getAll().forEach(t => t.kill());
	}
});
function pbmit_staticbox_hover() {
	var pbmit_var = jQuery('.pbmit-element-static-box-style-1, .pbmit-element-static-box-style-4, .pbmit-element-service-style-8');
	if (!pbmit_var.length) {
		return;
	}
	pbmit_var.each(function() {
		var pbmit_Class = ' .swiper-static-slide-nav li, .pbmit-hover-inner li, .pbmit-static-box-style-1, .pbmit-static-box-style-4';
		jQuery(this)
			.find(pbmit_Class).first()
			.addClass('pbmit-active');
		jQuery(this)
			.find(pbmit_Class)
			.on('mouseover', function() {
				jQuery(this).addClass('pbmit-active').siblings().removeClass('pbmit-active');
			});
	});
}
function pbmit_portfolio9_heading_animation() {
	var pbmit_var1 = jQuery('.pbmit-element-portfolio-style-9');
	if (!pbmit_var1.length) {
		return;
	}
	ScrollTrigger.matchMedia({
		"(min-width: 768px)": function() {
			const pbmit_line		= gsap.utils.toArray(".pbmit-heading-animation .pbmit-heading-text1");
			const pbmit_ani_img		= document.querySelector(".pbmit-ani-image img");
			const pbmit_heading_ani = gsap.timeline({
				scrollTrigger: {
				trigger: ".pbmit-heading-animation",
				start: "top top",
				end: "+=40%",
				pin: true,
				scrub: true,
				pinSpacing: true
				}
			});
			pbmit_heading_ani.to(pbmit_line, {
				opacity: 1,
				y: 0,
				stagger: 0.3,
				duration: 1,
				ease: "none"
			})
			.fromTo( pbmit_ani_img,
			{ width: 0, opacity: 0.2 },
			{ width: "auto", opacity: 1, duration: 1, ease: "none" },
			"<0.2" );
			return () => pbmit_heading_ani.kill();
		},
		"(max-width: 767px)": function() {
			ScrollTrigger.getAll().forEach(st => st.kill());
		}
	});
}
function pbmit_card_static_box() {
  const container = document.querySelector('.pbmit-element-static-box-style-5');
  if (!container) return;
  ScrollTrigger.matchMedia({
	"(min-width: 1025px)": () => {
	  const panels = gsap.utils.toArray(".pbmit-box-wrapper");
	  const headingSticky = document.querySelector('.pbmit-heading-box-sticky');
	  const btnSticky = document.querySelector('.pbmit-btn-box-sticky');
	  if (!panels.length) return;
	  const panelHeight = panels[0].offsetHeight + 80;
	  const topSpacing = 80;
	  panels.forEach((panel, i) => {
		gsap.set(panel, { top: i * 50 });
		gsap.to(panel, {
		  scrollTrigger: {
			trigger: panel,
			start: `top bottom-=100`,
			end: `top+=${80 + panels.length * 2}`,
			scrub: true,
		  },
		  ease: "none",
		  scale: 1 - (panels.length - i) * 0.025,
		});
		ScrollTrigger.create({
		  trigger: panel,
		  start: "top 80px",
		  endTrigger: container,
		  end: `bottom top+=${panelHeight + panels.length}`,
		  pin: true,
		  pinSpacing: false,
		});
	  });
	  if (headingSticky || btnSticky) {
		gsap.to(headingSticky, {
		  scrollTrigger: {
			trigger: container,
			start: `top top+=${topSpacing}`,
			end: `bottom top+=${panelHeight + panels.length}`,
			scrub: true,
			pin: headingSticky,
			pinSpacing: false,
		  }
		});
		gsap.to(btnSticky, {
		  scrollTrigger: {
			trigger: container,
			start: `top top+=${topSpacing}`, // same as heading
			end: `bottom top+=${panelHeight + panels.length}`,
			scrub: true,
			pin: btnSticky,
			pinSpacing: false,
		  }
		});
	  }
	},
	"(max-width:1024px)": () => {
	  ScrollTrigger.getAll().forEach(st => st.kill(true));
	}
  });
}
function pbmit_miconheading_scroll() {
  var $container = jQuery('.pbmit-scrolling .pbmit-element-miconheading-style-26 .pbmit-element-inner');
  if (!$container.length) return;

  var topSpacing = 200;

  ScrollTrigger.matchMedia({
    "(min-width: 1025px)": function () {
		var $header = $container.find('.pbmit-ele-header-area');
		var $posts  = $container.find('.pbmit-element-posts-wrapper');
		var headerHeight   = $header.outerHeight();
		var postsHeight    = $posts[0].scrollHeight;
		var viewportHeight = window.innerHeight;

		gsap.set($posts[0], { y: 500 });

		ScrollTrigger.create({
			trigger: $container[0],
			start: "top top",
			end: () => `+=${postsHeight - viewportHeight + headerHeight + topSpacing}`,
			pin: true,
			pinSpacing: false,
			scrub: 1.2
		});
		gsap.fromTo(
			$posts[0],
			{ y: 500 },
			{
				y: () => -(postsHeight - viewportHeight + headerHeight + topSpacing),
				ease: "none",
				scrollTrigger: {
				trigger: $container[0],
				start: "top top",
				pinSpacing: false,
				end: () => `+=${postsHeight - viewportHeight + headerHeight + topSpacing}`,
				scrub: 1.2
				}
			}
		);
    },
    "(max-width: 1024px)": function () {
		ScrollTrigger.getAll().forEach(st => st.kill(true));
		topSpacing = 0;

		var $posts = $container.find('.pbmit-element-posts-wrapper');
		var $header = $container.find('.pbmit-ele-header-area');

		gsap.set($posts[0], { y: 0, transition: 'none' });
		gsap.set($header[0], { position: 'relative', top: 'auto' });
	}
  });
}

function pbmit_testimonial_animation() {
  ScrollTrigger.matchMedia({
	"(min-width: 768px)": () => {
	  var triggerEl = document.querySelector('.pbmit-testimonial-sticky');
	  var pinEl = triggerEl;
	  var startPos = "top top";
	  if (!triggerEl) {
		triggerEl = document.querySelector('.pbmit-element-testimonial-style-11 .pbmit-ele-header-area');
		pinEl = document.querySelector('.pbmit-element-testimonial-style-11');
		startPos = "top 50px";
	  }
	  if (!triggerEl || !pinEl) return;
	  var areas = gsap.utils.toArray(".pbmit-testimonial-style-11");
	  var itemsToAnimate = areas.slice(1).reverse();
	  itemsToAnimate.forEach(function (item, index) {
		gsap.set(item, {
		  rotate: -(index * 2) - 2,
		  yPercent: 0,
		  willChange: "transform"
		});
	  });
	  var pbmit = gsap.timeline({
		scrollTrigger: {
		  trigger: triggerEl,
		  pin: pinEl,
		  start: startPos,
		  end: "+=" + (itemsToAnimate.length * 300),
		  scrub: 1.5,
		  pinSpacing: true
		}
	  });
	  itemsToAnimate.forEach(function (item, index) {
		pbmit.to(item, {
		  yPercent: -200,
		  rotate: 0,
		  ease: "power1.out"
		}, index * 0.3);
	  });
	}
  });
}
// on ready
jQuery(document).ready(function() {
	pbmit_title_animation();
	pbmit_extend_section();
	pbmit_portfolio4_slider();
	pbmit_ihbox_move();
	pbmit_staticbox_hover();
	pbmit_portfolio9_heading_animation();
	pbmit_miconheading_scroll();
	pbmit_testimonial_animation();
});
// on resize
jQuery(window).resize(function() {
	pbmit_title_animation();
	pbmit_img_animation();	
});
// on load
jQuery(window).on('load', function() {
	pbmit_img_animation();
	pbmit_sticky();
	pbmit_set_tooltip();
	pbmit_squire_image();
	pbmit_animate_custom_text();
	pbmit_title_animation();
	pbmit_card_static_box();
	jQuery('[data-magnetic]').each(function() { new Magnetic(this); });
	gsap.delayedCall(1, () =>
		ScrollTrigger.getAll().forEach((t) => {
			t.refresh();
		})
	);	 
});