(function initIndustryProductsPage(global) { function initIndustryProductsTabsReveal() { const tabsEl = document.querySelector("[data-industry-tabs-reveal]"); if (!tabsEl) return; const prefersReducedMotion = global.matchMedia && global.matchMedia("(prefers-reduced-motion: reduce)").matches; const revealTabs = () => { tabsEl.classList.add("is-visible"); }; const observeTabs = () => { if (prefersReducedMotion || !("IntersectionObserver" in global)) { revealTabs(); return; } const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (!entry.isIntersecting) { return; } revealTabs(); observer.unobserve(entry.target); }); }, { rootMargin: "0px 0px -10% 0px", threshold: 0.16, }); observer.observe(tabsEl); }; const waitForTabs = (attempt = 0) => { if (tabsEl.querySelectorAll(".industry-products-tab").length > 0) { observeTabs(); return; } if (attempt >= 24) { revealTabs(); return; } global.requestAnimationFrame(() => { waitForTabs(attempt + 1); }); }; waitForTabs(); } function createIndustryProductsPageState() { const panelSwitchDuration = 620; let panelSwitchTimer = 0; const getProductIndex = (items, key) => items.findIndex((item) => item === key); const getProductKeys = () => Array.from( document.querySelectorAll(".industry-products-tab[data-product-key]") ).map((item) => (item.getAttribute("data-product-key") || "").trim()).filter(Boolean); const getRequestedKey = () => { try { const params = new URLSearchParams(global.location.search || ""); const key = params.get("tab") || params.get("product") || ""; return key.trim().toLowerCase(); } catch (error) { return ""; } }; const updateUrlForKey = (key) => { if (!key || !global.history || typeof global.history.replaceState !== "function") { return; } try { const nextUrl = new URL(global.location.href); nextUrl.searchParams.set("tab", key); global.history.replaceState({}, "", nextUrl.toString()); } catch (error) { // ignore URL update failures } }; const clearPanelSwitchTimer = () => { if (!panelSwitchTimer) return; global.clearTimeout(panelSwitchTimer); panelSwitchTimer = 0; }; return { activeKey: "coal", leavingKey: "", transitionDirection: 1, productKeys: [], init() { this.productKeys = getProductKeys(); if (this.productKeys.length > 0 && !this.productKeys.includes(this.activeKey)) { this.activeKey = this.productKeys[0]; } const requestedKey = getRequestedKey(); if (!requestedKey || !this.productKeys.includes(requestedKey)) { return; } this.activeKey = requestedKey; updateUrlForKey(requestedKey); }, setActive(key) { if (!key || key === this.activeKey) { return; } const currentIndex = getProductIndex(this.productKeys, this.activeKey); const nextIndex = getProductIndex(this.productKeys, key); if (nextIndex === -1) { return; } this.transitionDirection = currentIndex === -1 || nextIndex > currentIndex ? 1 : -1; this.leavingKey = this.activeKey; this.activeKey = key; updateUrlForKey(key); clearPanelSwitchTimer(); panelSwitchTimer = global.setTimeout(() => { this.leavingKey = ""; }, panelSwitchDuration); }, isActiveProduct(key) { return key === this.activeKey; }, pressedValue(key) { return this.isActiveProduct(key) ? "true" : "false"; }, hiddenValue(key) { return this.isActiveProduct(key) ? "false" : "true"; }, activeTitleId(key) { return this.isActiveProduct(key) ? "industry-products-title" : null; }, isVisiblePanel(key) { return key === this.activeKey || key === this.leavingKey; }, panelClasses(key) { return { "is-active": key === this.activeKey, "is-leaving": key === this.leavingKey, "is-forward": this.transitionDirection === 1, "is-backward": this.transitionDirection === -1 }; } }; } global.createIndustryProductsPageState = createIndustryProductsPageState; if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", initIndustryProductsTabsReveal, { once: true }); } else { initIndustryProductsTabsReveal(); } })(window);