HEX
Server: nginx/1.24.0
System: Linux 0c1023d6c65e 6.8.0-137-generic #137-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 17 20:28:23 UTC 2026 x86_64
User: root (0)
PHP: 8.3.33
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/themes/thegem-elementor/js/ethnic-home-hero.js
(() => {
	const reducedMotionQuery = window.matchMedia('(prefers-reduced-motion: reduce)');

	const initIntroOverlay = () => {
		const overlay = document.querySelector('[data-intro-overlay]');

		if (!overlay || overlay.dataset.introInitialized === 'true') {
			return;
		}

		overlay.dataset.introInitialized = 'true';

		const visibleDurationRaw = Number.parseInt(overlay.dataset.introDuration || '4000', 10);
		const visibleDuration = Number.isNaN(visibleDurationRaw) ? 4000 : Math.max(0, visibleDurationRaw);
		const hideDuration = reducedMotionQuery.matches ? 80 : 760;
		const pageBody = document.body;
		const headerLogoImages = Array.from(
			document.querySelectorAll('#site-header .thegem-te-logo img, .header-sticky-template .thegem-te-logo img')
		);
		const logoSwapMap = {
			logo_e1057649409e5e93ffa2d960c8793f83: 'logo_908ea5c0901843850e2a325e62cef548',
			logo_fcc204487a79f5c9ae29b165e9ef910b: 'logo_d2950fafb968a6a1a98b941e19e4be96',
		};

		let hasHidden = false;
		let finalizeTimer = null;

		const swapLogoAssetToken = (value) => {
			if (!value) {
				return value;
			}

			return Object.entries(logoSwapMap).reduce((nextValue, [fromToken, toToken]) => {
				return nextValue.replace(new RegExp(fromToken, 'g'), toToken);
			}, value);
		};

		const swapHeaderLogosForIntro = () => {
			headerLogoImages.forEach((image) => {
				if (!image.dataset.introOriginalSrc) {
					image.dataset.introOriginalSrc = image.getAttribute('src') || '';
				}

				if (!image.dataset.introOriginalSrcset) {
					image.dataset.introOriginalSrcset = image.getAttribute('srcset') || '';
				}

				const originalSrc = image.dataset.introOriginalSrc;
				const originalSrcset = image.dataset.introOriginalSrcset;
				const swappedSrc = swapLogoAssetToken(originalSrc);
				const swappedSrcset = swapLogoAssetToken(originalSrcset);

				if (swappedSrc && swappedSrc !== image.getAttribute('src')) {
					image.setAttribute('src', swappedSrc);
				}

				if (originalSrcset) {
					image.setAttribute('srcset', swappedSrcset);
				}
			});
		};

		const restoreHeaderLogos = () => {
			headerLogoImages.forEach((image) => {
				if (typeof image.dataset.introOriginalSrc !== 'undefined') {
					if (image.dataset.introOriginalSrc) {
						image.setAttribute('src', image.dataset.introOriginalSrc);
					} else {
						image.removeAttribute('src');
					}
				}

				if (typeof image.dataset.introOriginalSrcset !== 'undefined') {
					if (image.dataset.introOriginalSrcset) {
						image.setAttribute('srcset', image.dataset.introOriginalSrcset);
					} else {
						image.removeAttribute('srcset');
					}
				}
			});
		};

		const unlockPage = () => {
			pageBody?.classList.remove('ethnic-home-intro-lock');
		};

		const finalizeHide = () => {
			if (hasHidden) {
				return;
			}

			hasHidden = true;
			overlay.classList.add('is-hidden');
			overlay.setAttribute('aria-hidden', 'true');
			overlay.setAttribute('inert', '');
			overlay.hidden = true;
			restoreHeaderLogos();
			unlockPage();
		};

		const beginHide = () => {
			if (hasHidden || overlay.classList.contains('is-hiding')) {
				return;
			}

			overlay.classList.add('is-hiding');
			overlay.setAttribute('aria-hidden', 'true');
			overlay.setAttribute('inert', '');
			finalizeTimer = window.setTimeout(finalizeHide, hideDuration + 90);
		};

		swapHeaderLogosForIntro();
		pageBody?.classList.add('ethnic-home-intro-lock');
		window.setTimeout(beginHide, visibleDuration);

		overlay.addEventListener('transitionend', (event) => {
			if (
				event.target !== overlay ||
				event.propertyName !== 'opacity' ||
				!overlay.classList.contains('is-hiding')
			) {
				return;
			}

			if (finalizeTimer) {
				window.clearTimeout(finalizeTimer);
				finalizeTimer = null;
			}

			finalizeHide();
		});
	};

	const initHeroNetworkMotion = () => {
		const hero = document.querySelector('.ethnic-home-hero');
		const network = hero?.querySelector('.ethnic-home-hero__network');

		if (!hero || !network || reducedMotionQuery.matches) {
			return;
		}

		let isHeroVisible = true;

		const setPausedState = (isPaused) => {
			hero.classList.toggle('is-network-paused', isPaused);
		};

		const syncState = () => {
			setPausedState(document.hidden || !isHeroVisible);
		};

		if (!('IntersectionObserver' in window)) {
			document.addEventListener('visibilitychange', syncState);
			return;
		}

		const observer = new IntersectionObserver(
			(entries) => {
				const entry = entries[0];

				if (!entry) {
					return;
				}

				isHeroVisible = entry.isIntersecting;
				syncState();
			},
			{
				threshold: 0.08,
				rootMargin: '120px 0px 120px 0px',
			}
		);

		observer.observe(hero);
		document.addEventListener('visibilitychange', syncState);
	};

	const initHeroSlider = () => {
		const root = document.querySelector('.ethnic-home-hero');

		if (!root) {
			return;
		}

		const stage = root.querySelector('.ethnic-home-hero__stage');
		const slides = Array.from(root.querySelectorAll('.ethnic-home-hero__slide'));
		const dots = Array.from(root.querySelectorAll('[data-hero-dot]'));
		const previousButton = root.querySelector('[data-hero-prev]');
		const nextButton = root.querySelector('[data-hero-next]');
		const currentCounter = root.querySelector('[data-hero-current]');
		const autoplayDelay = Number.parseInt(root.dataset.autoplay || '6000', 10);

		if (!stage || !slides.length) {
			return;
		}

		let activeIndex = slides.findIndex((slide) => slide.classList.contains('is-active'));
		let autoplayTimer = null;

		if (activeIndex < 0) {
			activeIndex = 0;
		}

		const syncStageHeight = () => {
			const activeSlide = slides[activeIndex];

			if (!activeSlide) {
				stage.style.height = '';
				return;
			}

			stage.style.height = `${activeSlide.offsetHeight}px`;
		};

		const updateNavigation = () => {
			slides.forEach((slide, index) => {
				const isActive = index === activeIndex;
				slide.classList.toggle('is-active', isActive);
				slide.setAttribute('aria-hidden', isActive ? 'false' : 'true');
			});

			dots.forEach((dot, index) => {
				const isActive = index === activeIndex;
				dot.classList.toggle('is-active', isActive);
				dot.setAttribute('aria-selected', isActive ? 'true' : 'false');
				dot.tabIndex = isActive ? 0 : -1;
			});

			if (currentCounter) {
				currentCounter.textContent = String(activeIndex + 1).padStart(2, '0');
			}

			syncStageHeight();
		};

		const goToSlide = (nextIndex) => {
			const slideCount = slides.length;
			activeIndex = ((nextIndex % slideCount) + slideCount) % slideCount;
			updateNavigation();
		};

		const stopAutoplay = () => {
			if (autoplayTimer) {
				window.clearInterval(autoplayTimer);
				autoplayTimer = null;
			}
		};

		const startAutoplay = () => {
			stopAutoplay();

			if (reducedMotionQuery.matches || slides.length < 2) {
				return;
			}

			autoplayTimer = window.setInterval(() => {
				goToSlide(activeIndex + 1);
			}, autoplayDelay);
		};

		const resetAutoplay = () => {
			startAutoplay();
		};

		previousButton?.addEventListener('click', () => {
			goToSlide(activeIndex - 1);
			resetAutoplay();
		});

		nextButton?.addEventListener('click', () => {
			goToSlide(activeIndex + 1);
			resetAutoplay();
		});

		dots.forEach((dot) => {
			dot.addEventListener('click', () => {
				const nextIndex = Number.parseInt(dot.dataset.heroDot || '0', 10);
				goToSlide(nextIndex);
				resetAutoplay();
			});
		});

		root.addEventListener('mouseenter', stopAutoplay);
		root.addEventListener('mouseleave', startAutoplay);
		root.addEventListener('focusin', stopAutoplay);
		root.addEventListener('keydown', (event) => {
			if (event.key === 'ArrowLeft') {
				event.preventDefault();
				goToSlide(activeIndex - 1);
				resetAutoplay();
			}

			if (event.key === 'ArrowRight') {
				event.preventDefault();
				goToSlide(activeIndex + 1);
				resetAutoplay();
			}
		});

		document.addEventListener('focusin', () => {
			if (!root.contains(document.activeElement)) {
				startAutoplay();
			}
		});

		window.addEventListener('resize', syncStageHeight, { passive: true });
		window.addEventListener('load', syncStageHeight);

		if (typeof ResizeObserver === 'function') {
			const resizeObserver = new ResizeObserver(() => {
				syncStageHeight();
			});

			slides.forEach((slide) => resizeObserver.observe(slide));
		}

		if (document.fonts && typeof document.fonts.ready === 'object') {
			document.fonts.ready.then(syncStageHeight).catch(() => {});
		}

		if (typeof reducedMotionQuery.addEventListener === 'function') {
			reducedMotionQuery.addEventListener('change', startAutoplay);
		}

		updateNavigation();
		startAutoplay();
	};

	const initServiceShowcase = () => {
		const showcases = Array.from(document.querySelectorAll('[data-service-showcase]'));

		if (!showcases.length) {
			return;
		}

		showcases.forEach((showcase) => {
			const cards = Array.from(showcase.querySelectorAll('[data-service-card]'));
			const panels = Array.from(showcase.querySelectorAll('[data-service-panel]'));
			const previousButton = showcase.querySelector('[data-service-prev]');
			const nextButton = showcase.querySelector('[data-service-next]');

			if (!cards.length || !panels.length) {
				return;
			}

			let activeCard = cards.find((card) => card.classList.contains('is-active')) || cards[0];

			const focusCard = (card) => {
				if (!card || typeof card.focus !== 'function') {
					return;
				}

				try {
					card.focus({ preventScroll: true });
				} catch (error) {
					card.focus();
				}
			};

			const setActiveCard = (nextCard, options = {}) => {
				if (!nextCard) {
					return;
				}

				const shouldScrollIntoView = options.scrollIntoView === true;

				const targetId = nextCard.dataset.serviceTarget;

				if (!targetId) {
					return;
				}

				activeCard = nextCard;

				cards.forEach((card) => {
					const isActive = card === nextCard;
					card.classList.toggle('is-active', isActive);
					card.setAttribute('aria-selected', isActive ? 'true' : 'false');
					card.tabIndex = isActive ? 0 : -1;
				});

				panels.forEach((panel) => {
					const isActive = panel.id === targetId;
					panel.classList.toggle('is-active', isActive);
					panel.hidden = !isActive;
				});

				if (shouldScrollIntoView && typeof nextCard.scrollIntoView === 'function') {
					nextCard.scrollIntoView({
						behavior: 'smooth',
						block: 'nearest',
						inline: 'nearest',
					});
				}
			};

			cards.forEach((card, index) => {
				card.addEventListener('click', () => {
					setActiveCard(card, { scrollIntoView: true });
				});

				card.addEventListener('focus', () => {
					setActiveCard(card);
				});

				card.addEventListener('keydown', (event) => {
					let nextIndex = index;

					if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {
						nextIndex = (index + 1) % cards.length;
					} else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {
						nextIndex = (index - 1 + cards.length) % cards.length;
					} else if (event.key === 'Home') {
						nextIndex = 0;
					} else if (event.key === 'End') {
						nextIndex = cards.length - 1;
					} else {
						return;
					}

					event.preventDefault();
					setActiveCard(cards[nextIndex], { scrollIntoView: true });
					focusCard(cards[nextIndex]);
				});
			});

			previousButton?.addEventListener('click', () => {
				const activeIndex = cards.indexOf(activeCard);
				const nextIndex = (activeIndex - 1 + cards.length) % cards.length;
				setActiveCard(cards[nextIndex], { scrollIntoView: true });
				focusCard(cards[nextIndex]);
			});

			nextButton?.addEventListener('click', () => {
				const activeIndex = cards.indexOf(activeCard);
				const nextIndex = (activeIndex + 1) % cards.length;
				setActiveCard(cards[nextIndex], { scrollIntoView: true });
				focusCard(cards[nextIndex]);
			});

			setActiveCard(activeCard);
		});
	};

	const initLoopingSliders = () => {
		const sliders = Array.from(document.querySelectorAll('[data-loop-slider]'));

		if (!sliders.length) {
			return;
		}

			sliders.forEach((slider) => {
				const track = slider.querySelector('[data-loop-track]');
				const originalSlides = Array.from(slider.querySelectorAll('[data-loop-slide]'));
				const alignmentMode = slider.dataset.loopAlign || 'start';
				const previousButton = slider.querySelector('[data-loop-prev]');
				const nextButton = slider.querySelector('[data-loop-next]');
				const dots = Array.from(slider.querySelectorAll('[data-loop-dot]'));
				const currentCounter = slider.querySelector('[data-loop-current]');
			const cloneCount = Math.min(
				Math.max(Number.parseInt(slider.dataset.loopClones || '1', 10) || 1, 1),
				originalSlides.length
			);

			if (!track || originalSlides.length < 2) {
				return;
			}

			const createClone = (slide, position) => {
				const clone = slide.cloneNode(true);
				clone.classList.remove('is-active');
				clone.setAttribute('aria-hidden', 'true');
				clone.removeAttribute('data-loop-slide');
				clone.dataset.loopClone = position;
				return clone;
			};

			const startClones = originalSlides.slice(-cloneCount).map((slide) => createClone(slide, 'start'));
			const endClones = originalSlides.slice(0, cloneCount).map((slide) => createClone(slide, 'end'));

			startClones.forEach((clone) => {
				track.insertBefore(clone, track.firstChild);
			});

			endClones.forEach((clone) => {
				track.appendChild(clone);
			});

			const trackSlides = Array.from(track.children);
			const loopStart = cloneCount;
			const loopEnd = cloneCount + originalSlides.length - 1;
			let activePosition = loopStart;
			let activeIndex = 0;
			let pendingResetPosition = null;
			let isTransitioning = false;

			const wrapPosition = (index) => ((index % trackSlides.length) + trackSlides.length) % trackSlides.length;
			const originalIndexFromPosition = (position) => ((position - loopStart) % originalSlides.length + originalSlides.length) % originalSlides.length;

				const getStepSize = () => {
				const slide = originalSlides[0];

				if (!slide) {
					return 0;
				}

				const styles = window.getComputedStyle(track);
				const gapValue = styles.columnGap || styles.gap || '0';
				const gap = Number.parseFloat(gapValue) || 0;
				const width = slide.getBoundingClientRect().width;

					return width + gap;
				};

				const getAlignmentOffset = () => {
					if ('center' !== alignmentMode) {
						return 0;
					}

					const frameWidth = track.parentElement?.getBoundingClientRect().width || slider.getBoundingClientRect().width;
					const activeSlide = trackSlides[activePosition] || originalSlides[0];
					const slideWidth = activeSlide?.getBoundingClientRect().width || 0;

					if (!frameWidth || !slideWidth) {
						return 0;
					}

					return Math.max((frameWidth - slideWidth) / 2, 0);
				};

			const updateState = (nextPosition) => {
				activePosition = wrapPosition(nextPosition);
				activeIndex = originalIndexFromPosition(activePosition);

				trackSlides.forEach((slide, index) => {
					const isActive = index === activePosition;
					slide.classList.toggle('is-active', isActive);
					slide.setAttribute('aria-hidden', isActive ? 'false' : 'true');
				});

				dots.forEach((dot, index) => {
					const isActive = index === activeIndex;
					dot.classList.toggle('is-active', isActive);
					dot.setAttribute('aria-selected', isActive ? 'true' : 'false');
					dot.tabIndex = isActive ? 0 : -1;
				});

				if (currentCounter) {
					currentCounter.textContent = String(activeIndex + 1).padStart(2, '0');
				}
			};

				const renderPosition = (animate) => {
					const stepSize = getStepSize();
					const alignmentOffset = getAlignmentOffset();

					if (!stepSize && !alignmentOffset) {
						return;
					}

					track.classList.toggle('is-instant', !animate);
					track.style.transform = `translate3d(${alignmentOffset - activePosition * stepSize}px, 0, 0)`;

				if (!animate) {
					track.offsetHeight;
					track.classList.remove('is-instant');
				}
			};

			const snapIfNeeded = () => {
				if (pendingResetPosition === null) {
					isTransitioning = false;
					return;
				}

				updateState(pendingResetPosition);
				renderPosition(false);
				pendingResetPosition = null;
				isTransitioning = false;
			};

			track.addEventListener('transitionend', (event) => {
				if (event.target !== track || event.propertyName !== 'transform') {
					return;
				}

				snapIfNeeded();
			});

			const goToPosition = (nextPosition, animate = true) => {
				if (isTransitioning && animate) {
					return;
				}

				const wrappedPosition = wrapPosition(nextPosition);
				const needsReset = wrappedPosition < loopStart
					? wrappedPosition + originalSlides.length
					: wrappedPosition > loopEnd
						? wrappedPosition - originalSlides.length
						: null;

				updateState(wrappedPosition);
				pendingResetPosition = needsReset;
				isTransitioning = animate && !reducedMotionQuery.matches;
				renderPosition(animate && !reducedMotionQuery.matches);

				if (!isTransitioning) {
					snapIfNeeded();
				}
			};

			previousButton?.addEventListener('click', () => {
				goToPosition(activePosition - 1);
			});

			nextButton?.addEventListener('click', () => {
				goToPosition(activePosition + 1);
			});

			dots.forEach((dot) => {
				dot.addEventListener('click', () => {
					const nextIndex = Number.parseInt(dot.dataset.loopDot || '0', 10);
					goToPosition(loopStart + nextIndex);
				});
			});

			track.addEventListener('keydown', (event) => {
				if (event.key === 'ArrowLeft') {
					event.preventDefault();
					goToPosition(activePosition - 1);
					return;
				}

				if (event.key === 'ArrowRight') {
					event.preventDefault();
					goToPosition(activePosition + 1);
					return;
				}

				if (event.key === 'Home') {
					event.preventDefault();
					goToPosition(loopStart);
					return;
				}

				if (event.key === 'End') {
					event.preventDefault();
					goToPosition(loopEnd);
				}
			});

			window.addEventListener('resize', () => {
				renderPosition(false);
			}, { passive: true });

			if (typeof ResizeObserver === 'function') {
				const resizeObserver = new ResizeObserver(() => {
					renderPosition(false);
				});

				resizeObserver.observe(slider);
				trackSlides.forEach((slide) => resizeObserver.observe(slide));
			}

			if (document.fonts && typeof document.fonts.ready === 'object') {
				document.fonts.ready.then(() => {
					renderPosition(false);
				}).catch(() => {});
			}

			updateState(activePosition);
			renderPosition(false);
		});
	};

	const initInsightsScroller = () => {
		const scrollers = Array.from(document.querySelectorAll('[data-insights-scroller]'));

		if (!scrollers.length) {
			return;
		}

		scrollers.forEach((scroller) => {
			let isPointerDown = false;
			let isDraggingHorizontally = false;
			let startX = 0;
			let startY = 0;
			let startScrollLeft = 0;
			let activePointerId = null;
			let suppressClickUntil = 0;

			const releasePointerCapture = () => {
				if (
					null !== activePointerId &&
					typeof scroller.hasPointerCapture === 'function' &&
					scroller.hasPointerCapture(activePointerId)
				) {
					scroller.releasePointerCapture(activePointerId);
				}
			};

			const endDrag = (event) => {
				if (!isPointerDown) {
					return;
				}

				const dragDistance = isDraggingHorizontally
					? Math.abs((event?.clientX || startX) - startX)
					: 0;

				isPointerDown = false;
				isDraggingHorizontally = false;
				releasePointerCapture();
				activePointerId = null;
				scroller.classList.remove('is-dragging');

				if (dragDistance > 6) {
					suppressClickUntil = Date.now() + 180;
				}
			};

			scroller.addEventListener('pointerdown', (event) => {
				if (event.pointerType === 'mouse' && event.button !== 0) {
					return;
				}

				isPointerDown = true;
				isDraggingHorizontally = false;
				startX = event.clientX;
				startY = event.clientY;
				startScrollLeft = scroller.scrollLeft;
				activePointerId = event.pointerId;
			});

			scroller.addEventListener('pointermove', (event) => {
				if (!isPointerDown) {
					return;
				}

				const delta = event.clientX - startX;
				const deltaY = event.clientY - startY;

				if (!isDraggingHorizontally) {
					const hasMeaningfulMovement = Math.max(Math.abs(delta), Math.abs(deltaY)) > 8;

					if (!hasMeaningfulMovement) {
						return;
					}

					if (Math.abs(deltaY) > Math.abs(delta)) {
						isPointerDown = false;
						activePointerId = null;
						scroller.classList.remove('is-dragging');
						return;
					}

					isDraggingHorizontally = true;
					scroller.classList.add('is-dragging');

					if (typeof scroller.setPointerCapture === 'function') {
						scroller.setPointerCapture(event.pointerId);
					}
				}

				scroller.scrollLeft = startScrollLeft - delta;
			});

			scroller.addEventListener('pointerup', (event) => {
				endDrag(event);
			});

			scroller.addEventListener('pointercancel', (event) => {
				endDrag(event);
			});

			scroller.addEventListener('lostpointercapture', () => {
				isPointerDown = false;
				isDraggingHorizontally = false;
				activePointerId = null;
				scroller.classList.remove('is-dragging');
			});

			scroller.addEventListener('click', (event) => {
				if (Date.now() > suppressClickUntil) {
					return;
				}

				const anchor = event.target.closest('a');

				if (!anchor || !scroller.contains(anchor)) {
					return;
				}

				event.preventDefault();
				event.stopPropagation();
			}, true);

			scroller.addEventListener('dragstart', (event) => {
				event.preventDefault();
			});

			scroller.addEventListener('keydown', (event) => {
				if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') {
					return;
				}

				event.preventDefault();
				const direction = event.key === 'ArrowRight' ? 1 : -1;
				const offset = Math.max(220, Math.round(scroller.clientWidth * 0.64)) * direction;

				scroller.scrollBy({
					left: offset,
					behavior: reducedMotionQuery.matches ? 'auto' : 'smooth',
				});
			});
		});
	};

	const initFaqAccordion = () => {
		const accordions = Array.from(document.querySelectorAll('[data-faq-accordion]'));

		if (!accordions.length) {
			return;
		}

		accordions.forEach((accordion) => {
			const faqItems = Array.from(accordion.querySelectorAll('[data-faq-item]'))
				.map((item) => ({
					item,
					trigger: item.querySelector('[data-faq-trigger]'),
					panel: item.querySelector('[data-faq-panel]'),
				}))
				.filter(({ trigger, panel }) => trigger && panel);

			if (!faqItems.length) {
				return;
			}

			const setItemState = (faqItem, isOpen) => {
				const { item, trigger, panel } = faqItem;

				item.classList.toggle('is-open', isOpen);
				trigger.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
				panel.setAttribute('aria-hidden', isOpen ? 'false' : 'true');
				panel.hidden = false;

				if (isOpen) {
					window.requestAnimationFrame(() => {
						panel.style.maxHeight = `${panel.scrollHeight}px`;
					});
					return;
				}

				panel.style.maxHeight = '0px';
			};

			const openItem = (targetItem) => {
				faqItems.forEach((faqItem) => {
					setItemState(faqItem, faqItem === targetItem);
				});
			};

			faqItems.forEach((faqItem) => {
				setItemState(faqItem, false);
			});

			faqItems.forEach((faqItem, index) => {
				const { trigger, item } = faqItem;

				trigger.addEventListener('click', () => {
					if (item.classList.contains('is-open')) {
						setItemState(faqItem, false);
						return;
					}

					openItem(faqItem);
				});

				trigger.addEventListener('keydown', (event) => {
					let nextIndex = null;

					if (event.key === 'ArrowDown') {
						nextIndex = (index + 1) % faqItems.length;
					} else if (event.key === 'ArrowUp') {
						nextIndex = (index - 1 + faqItems.length) % faqItems.length;
					} else if (event.key === 'Home') {
						nextIndex = 0;
					} else if (event.key === 'End') {
						nextIndex = faqItems.length - 1;
					}

					if (null === nextIndex) {
						return;
					}

					event.preventDefault();
					faqItems[nextIndex].trigger.focus();
				});
			});

			window.addEventListener(
				'resize',
				() => {
					const openFaqItem = faqItems.find(({ item }) => item.classList.contains('is-open'));

					if (!openFaqItem) {
						return;
					}

					openFaqItem.panel.style.maxHeight = `${openFaqItem.panel.scrollHeight}px`;
				},
				{ passive: true }
			);
		});
	};

	const initCounters = () => {
		const counters = Array.from(document.querySelectorAll('[data-ethnic-count-to]'));

		if (!counters.length) {
			return;
		}

		const renderFinalValue = (element, endValue) => {
			element.textContent = new Intl.NumberFormat('en-US').format(endValue);
		};

		const animateCounter = (element) => {
			const endValue = Number.parseInt(element.dataset.ethnicCountTo || '0', 10);
			const duration = Number.parseInt(element.dataset.ethnicCountDuration || '800', 10);

			if (Number.isNaN(endValue)) {
				return;
			}

			const bounds = element.getBoundingClientRect();
			const isInitiallyVisible = bounds.top < window.innerHeight * 0.92 && bounds.bottom > 0;

			if (reducedMotionQuery.matches || isInitiallyVisible) {
				renderFinalValue(element, endValue);
				return;
			}

			const startTime = performance.now();

			const tick = (now) => {
				const progress = Math.min((now - startTime) / duration, 1);
				const eased = 1 - Math.pow(1 - progress, 3);
				const value = Math.round(endValue * eased);
				element.textContent = new Intl.NumberFormat('en-US').format(value);

				if (progress < 1) {
					window.requestAnimationFrame(tick);
				}
			};

			window.requestAnimationFrame(tick);
		};

		if (!('IntersectionObserver' in window)) {
			counters.forEach((counter) => animateCounter(counter));
			return;
		}

		const observer = new IntersectionObserver(
			(entries) => {
				entries.forEach((entry) => {
					if (!entry.isIntersecting) {
						return;
					}

					animateCounter(entry.target);
					observer.unobserve(entry.target);
				});
			},
			{
				threshold: 0.2,
			}
		);

		counters.forEach((counter) => observer.observe(counter));
	};

	initIntroOverlay();
	initHeroNetworkMotion();
	initHeroSlider();
	initServiceShowcase();
	initLoopingSliders();
	initInsightsScroller();
	initFaqAccordion();
	initCounters();
})();