(()=>{"use strict";const e=class{static slug="";run(){}getState(){return{}}},t=class extends e{static slug="comment";run(){const e=new CustomEvent("showOverlay",{detail:"comments-overlay"});window.dispatchEvent(e);const t=document.querySelector("#comments-title");t instanceof Element&&t.scrollIntoView()}},o=class extends e{static slug="contest";run(){console.log("ContestIntent")}},n=e=>{const{apiUrl:t,namespace:o="heavy/v1"}=heavyApi;return s.reduceRight(((e,t)=>o=>t(o,e)),(e=>{let n,s,{url:r,path:a,endpoint:c,headers:i,body:l,data:d,...u}=e;"string"==typeof c&&(n=o.replace(/^\/|\/$/g,""),s=c.replace(/^\//,""),a=s?n+"/"+s:n),"string"==typeof a&&(-1!==t.indexOf("?")&&(a=a.replace("?","&")),a=a.replace(/^\//,""),r=t+a),i={Accept:"application/json, */*;q=0.1",...i},delete i["X-WP-Nonce"],d&&(l=JSON.stringify(d),i["Content-Type"]="application/json");const m={code:"fetch_error",message:"You are probably offline."},v={code:"invalid_json",message:"The response is not a valid JSON response."};return window.fetch(r||a||window.location.href,{...u,headers:i,body:l}).then((e=>Promise.resolve(e).then((e=>{if(e.status>=200&&e.status<300)return e;throw e})).then((e=>{if(204===e.status)return null;if(e&&e.json)return e.json().catch((()=>{throw v}));throw v}))),(()=>{throw m}))}))(e)},s=[];n.use=e=>{s.unshift(e)};const r={init(){const e=document.createElement("div");e.classList.add("c-toast-container"),document.body.appendChild(e),document.addEventListener("heavy:toast",(e=>{const{message:t,type:o}=e.detail;r.show(t,o)}))},show(e,t=null,o=null){const n=Array.from(document.querySelectorAll(".c-toast")).find((t=>t.innerText===e));if(n)return;const s=document.createElement("div");s.classList.add("c-toast"),null!==t&&s.classList.add(`is-${t}`),null===o&&(o="error"===t?1e4:5e3),s.innerText=e,document.querySelector(".c-toast-container").appendChild(s),setTimeout((()=>s.parentNode.removeChild(s)),o)}},a=r,c={interval:250,maxWait:8e3,available(e,t=c.interval,o=c.maxWait){return new Promise(((n,s)=>{const r=window.setInterval((()=>{if(this.findVarByName(e))return n(),clearTimeout(a),void clearInterval(r)}),t),a=window.setTimeout((function(){clearTimeout(r),s()}),o)}))},findVarByName(e){let t=0,o=e.split("."),n=window;try{for(;null!=n&&t{if(!e)return;const n=()=>{const n={method:t};o&&(n.id=o),window.gtag("event",e,n)};i.available("gtag").then((()=>{"requestIdleCallback"in window?requestIdleCallback(n):n()})).catch((()=>{console.error("Failed to TrackAnalytics, gtag unavailable.")}))},d={init(e,t={}){this.form=e,this.nameInput=this.form.querySelector('[name="name"]'),this.emailInput=this.form.querySelector('[name="email"]'),this.isSubmitting=!1,this.formSubmitButton=this.form.querySelector('[type="submit"]'),this.formCheckboxes=this.form.querySelectorAll('[type="checkbox"]');const{focusInput:o=!0}=t;o&&this.focusNameInput(),this.autoFillData(),this.onFillForm(),this.attachEvents()},async submit(e){const t=this;let o=e?.target,s=!1;if(o||(o=t.form),!o)return s;if(this.isSubmitting)return s;t.setIsSubmitting(!0);const r={name:o.querySelector('[name="name"]')?.value,email:o.querySelector('[name="email"]')?.value,lists:t.getListIdKeys(o)};try{const t=await n({endpoint:"subscribe",method:"POST",data:r});s=this.displayMessage(t),setTimeout((()=>{l({eventName:"sign_up",eventId:s?"subscribe-form":"subscribe-form-error",eventMethod:e?"manual":"auto"})}),0)}catch(e){this.displayErrorMessage(e),s=!1}return t.setIsSubmitting(!1),s},getListIdKeys(e){const t=e.querySelector('[name="list-api-id"]')?.value||"",o=e.querySelector('[name="list-alert-api-id"]')?.value||"",n=[];return e.querySelector('[name="list-news"]')?.checked&&n.push(t),e.querySelector('[name="list-alerts"]')?.checked&&n.push(o),n},attachEvents(){const e=this;e.form.addEventListener("submit",(t=>{t.preventDefault(),e.submit(t)}))},focusNameInput(){const e=this;e.nameInput&&setTimeout((()=>e.nameInput.focus()),0)},setIsSubmitting(e){const t=this;if(this.isSubmitting=e,!t.form)return;const o=t.form.querySelector(".c-subscribe-form__submit");e?(t.form.classList.add("is-submitting"),o.setAttribute("disabled","disabled")):(t.form.classList.remove("is-submitting"),o.removeAttribute("disabled"))},displayErrorMessage(e){self=this;const t=this.form.querySelector(".c-subscribe-form__message");t&&(t.classList.remove("is-success"),t.classList.add("is-error"),t.textContent=heavySubscribe.error+" ("+parseInt(e.status)+")",a.show(heavySubscribe.error,"error"))},displayMessage({response:{code:e},body:t}){self=this;const o=this.form.querySelector(".c-subscribe-form__message");let n="",s=!1;if(o){if(o.classList.remove("is-success"),o.classList.remove("is-error"),o.textContent="",201===e)n=heavySubscribe.success,o.classList.add("is-success"),document.dispatchEvent(new CustomEvent("heavy:subscribed")),s=!0;else{const e=JSON.parse(t);o.classList.add("is-error"),n=e.Message}return a.show(n,s?"success":"error"),o.textContent=n,s}},autoFillData(){const e=this,t=document.cookie.split("; ").find((e=>e.startsWith("fp.user=")));let o,n,s;if(o=t?JSON.parse(t.substring(8)):null,n=o?.user_name,s=o?.user_email,!n){const e=localStorage.getItem("fp.user");e&&(o=JSON.parse(e),n=o?.user_name,s=o?.user_email)}n&&(e.nameInput.value=n),s&&(e.emailInput.value=s),e.formSubmitButton.disabled=!e.filledInForm()},filledInForm(){const e=this;let t=!1,o=!1;return 0===e.formCheckboxes.length&&""!==e.emailInput.value||(e.formCheckboxes.forEach((e=>{e.checked&&(o=!0)})),o&&""!==e.emailInput.value&&(t=!0),t)},onFillForm(){const e=this;e.emailInput.addEventListener("input",(()=>{e.formSubmitButton.disabled=!e.filledInForm()})),e.formCheckboxes.forEach((t=>{t.addEventListener("change",(()=>{e.formSubmitButton.disabled=!e.filledInForm()}))}))}},u=(e,t,o)=>{if("function"!=typeof o)return;const n=e=>{e.forEach((e=>{const n="_hasEventHandler_"+t;e[n]||(e.addEventListener(t,o),e[n]=!0)}))};n(document.querySelectorAll(e)),document.addEventListener("heavy:overlayOpen",(t=>{var o;const{overlay:s}=t.detail;n(null!==(o=s.querySelectorAll(e))&&void 0!==o?o:[])})),document.addEventListener("heavy:modalOpen",(t=>{var o;const{modal:s}=t.detail;n(null!==(o=s.querySelectorAll(e))&&void 0!==o?o:[])}))},m=async()=>new Promise((e=>{setTimeout(e,0)})),v={init(){u(".c-select__button","click",(e=>{const t=e.target,o=t.closest(".c-select"),n=o.querySelectorAll(".c-select__dropdown li");o.classList.toggle("active"),t.setAttribute("aria-expanded","true"===t.getAttribute("aria-expanded")?"false":"true"),n.forEach((e=>{e.addEventListener("click",(t=>v.handler(t,o,e)))}));const s=({target:e})=>{document.removeEventListener("click",s),o.contains(e)||(o.classList.remove("active"),t.setAttribute("aria-expanded","false"))};o.classList.contains("active")&&setTimeout((()=>{document.addEventListener("click",s)}),100)}))},handler(e,t,o){const n=t.querySelector(".c-select__value"),s=o.querySelector("[type=radio]");"click"===e.type&&0!==e.clientX&&0!==e.clientY&&(n.dataset.previousValue=n.textContent?.trim(),setTimeout((()=>{n.textContent=o.textContent,t.classList.remove("active"),s.click()}),0))},revertToPreviousValue(e){const t=e.querySelector(".c-select__value"),o=e.querySelectorAll("[type=radio]"),{previousValue:n=""}=t.dataset;t.textContent=n,[...o].find((e=>e.value.trim()===n)).checked=!0}},h=v,y={init(){const e=new Map([["play-in-tournament","PIT"],["regular-season","REG"],["postseason","PST"],["preseason","PRE"]]);u("[type=radio][name=season_years]","change",(async t=>{const o=document.querySelector(".c-overlay .c-overlay__content");if(null===o)return;o.classList.add("is-loading");const n=t.target,{nonce:s,year:r,league:a,overlay:c,entity:i,id:l}=n.dataset,d=document.getElementById(c)?.querySelector('.tabs [aria-selected="true"]')?.dataset?.label,u={action:"sport_seasons_overlay",_wpnonce:s,season_year:r,active_type:e.get(d)||"REG",league:a,overlay:c,entity:i,id:l},m=await y.getMarkup(u);if(null===m)return h.revertToPreviousValue(n.closest(".c-select")),void o.classList.remove("is-loading");const v=(new DOMParser).parseFromString(m,"text/html");requestAnimationFrame((function(){o.innerHTML=v?.querySelector(".c-overlay__content")?.innerHTML;const e=new CustomEvent("heavy:overlayOpen",{detail:{overlay:o}});document.dispatchEvent(e),o.classList.remove("is-loading")}))}))},prepareFormData(e){const t=new FormData;return Object.keys(e).forEach((o=>{t.append(o,e[o])})),t},async getMarkup(e){let t=null;try{const o=await fetch(heavyJS.ajaxurl,{method:"POST",body:y.prepareFormData(e)}),{data:n,success:s}=await o.json();if(!s)throw new Error(n?.message);if(t=n?.html?n.html:null,!t)throw new Error("Cannot fetch the data, please try again later.")}catch(e){a.show(e.message,"error")}finally{return t}}},g=y,f={triggerSelector:"[data-overlay-target]",init(){const e=document.querySelector(f.triggerSelector),t=document.querySelector(".c-overlay");if(!e||!t)return;u(f.triggerSelector+':not([data-overlay-target^="subscribe-form"])',"click",f.show),u(".c-overlay__close","click",f.close),setTimeout(g.init,0);const o=window.location.hash.substring(1);if(o.startsWith("subscribe-form"))return;let n;n=o.startsWith("team-news")?document.getElementById("team-news"):o.startsWith("comment")?document.getElementById("comments-overlay"):document.getElementById(o),n instanceof Element&&f.showOverlay(n),window.addEventListener("showOverlay",(function(e){if(!e.detail)return void console.warn('showOverlay event received without detail. Expected format: { detail: "elementId" }');const t=document.getElementById(e.detail);t instanceof Element&&f.showOverlay(t)})),document.addEventListener("keydown",(e=>{"Escape"===e.key&&f.close()})),document.addEventListener("heavy:modalOpen",f.close)},show(e){const t=e.target.closest("[data-overlay-target]"),o=t.dataset.overlayTarget,n=t.dataset.overlayScrollTo;if(o.startsWith("subscribe-form"))return;if(!o)return;if(window.location.hash.substring(1)===o)return;const s=document.getElementById(o);s&&f.showOverlay(s,t),window.history.replaceState({overlay:!0,overlayScrollTo:n},"",window.location.pathname+"#"+o),n&&f.scrollTo(n)},showOverlay(e,t){const o=document.querySelector(".c-overlay"),n=t?.dataset?.tabTarget;if(!e||!o)return;let s=document.querySelector(".c-overlay__background"),r=e.dataset.overlayRender;const a=e.dataset.overlayType;if(!s){const e=document.createElement("div");e.classList.add("c-overlay__background"),o.before(e),s=document.querySelector(".c-overlay__background")}document.documentElement.classList.add("is-overlay-open"),f.removeOverlay(o),o.classList.add("is-active"),r&&(r=r.replace(/[^a-z0-9-_]/g,""),o.classList.add(`is-${r}`)),setTimeout((()=>{let t,s,r;if(t="dynamic"===a?e.querySelector(".h-template"):e.content?e.content.cloneNode(!0):e.cloneNode(!0),document.body.classList.contains("home")&&(t.id=e.getAttribute("id")?`${e.id}-overlay`:null),"team-news"===e.id){const e=window.location.hash.substring(1);let o="";if(e.startsWith("team-news")){const t=e.split("-");o=t.length>2?parseInt(t[2]):""}if(o){const e=t.querySelector(`#team-news-${o}`);e&&e.classList.add("c-alert--focused")}}o.appendChild(t);const c=o.querySelector(".c-overlay__header");c.addEventListener("touchstart",(function(e){s=e.touches[0].clientY}),{passive:!0}),c.addEventListener("touchmove",(function(e){const t=e.touches[0].clientY;r=s-t}),{passive:!0}),c.addEventListener("touchend",(function(){r<-25&&f.close()})),o.scrollTop=0,u(".c-heavy-sports-table--sortable th:not(.c-heavy-sports-th--non-sortable)","click",f.sortTable);const i=o.querySelector(".js-overlay__close");i&&i.addEventListener("click",f.close);const l=new CustomEvent("heavy:overlayOpen",{detail:{overlay:o}});if(document.dispatchEvent(l),n){const e=o.querySelector(`button[data-label=${n}]`);e&&e.click()}}),0),s.addEventListener("click",f.close),setTimeout((()=>{l({eventName:"overlay_open",eventId:e.id,eventMethod:t?"click":"auto"})}),0)},close(){const e=document.querySelector(".c-overlay"),t=document.querySelector(".js-overlay__close");if(document.documentElement.classList.remove("is-overlay-open"),!e||!t||!e.classList.contains("is-active"))return;const o=document.querySelector(".c-overlay__background");e.classList.remove("is-active"),e.classList.forEach((t=>{t.startsWith("is-")&&e.classList.remove(t)})),t.removeEventListener("click",f.close),o.removeEventListener("click",f.close),window.history.replaceState({overlay:!1},"",window.location.pathname)},removeOverlay(e){let t;e&&(e.firstChild?.dataset?.parent&&(t=document.getElementById(e.firstChild?.dataset.parent)),t&&t.append(...e.childNodes),e.innerHTML="")},sortTable(e){const t=e.target.closest("th"),o=t.closest("table"),n=o.querySelectorAll("tbody");n&&(o.querySelectorAll("th").forEach((e=>{e.classList.remove("c-heavy-sports-th--sorted")})),n.forEach((e=>{Array.from(e.querySelectorAll("tbody tr:not(:has(.c-heavy-sports-table__series_title))")).sort(f.compare(Array.from(t.parentNode.children).indexOf(t),this.asc)).forEach((t=>e.appendChild(t)))})),this.asc=!this.asc,t.classList.add("c-heavy-sports-th--sorted"),t.classList.toggle("c-heavy-sports-th--sorted-asc"))},compare(e,t){const o=(e,t)=>{var o;const n=e.children[t];return n?(null!==(o=n.dataset?.sortValue)&&void 0!==o?o:n.querySelector("[data-sort-value]")?.dataset.sortValue)||n.innerText||n.textContent:""};return(n,s)=>{return r=o(t?n:s,e),a=o(t?s:n,e),""===r||""===a||isNaN(r)||isNaN(a)?a.toString().localeCompare(r):a-r;var r,a}},scrollTo(e){if(!e)return;const t=document.querySelector(e),o=document.querySelector(".c-overlay"),n=o.querySelector(".c-overlay__header");t&&(t.scrollIntoView(),o.scrollBy(0,-n.offsetHeight))}},b=f;class p extends e{static slug="subscribe";static formSelector=".c-subscribe-form__form";getState(){const e=window.location.hash.substring(1);let t=null,o=document.getElementById(e);const n=e.startsWith("subscribe-form");return!o&&n&&(o=document.querySelector(L.modalsSelector)),o&&(t=o.querySelector(p.formSelector)),t?{ids:[...t.querySelectorAll(".c-subscribe-form__optin [type=checkbox]")].map((e=>{var t;return e.checked&&null!==(t=e.previousElementSibling?.value)&&void 0!==t?t:null})).filter((e=>null!==e))}:{}}async run(e){const{ids:t=[]}=e,o=window.location.hash.substring(1);let n=null,s=document.getElementById(o);const r=o.startsWith("subscribe-form");!s&&r&&(s=document.querySelector(L.modalsSelector)),s&&(n=s.querySelector(p.formSelector),n&&([...n.querySelectorAll(".c-subscribe-form__optin [type=checkbox]")].forEach((e=>{var o;const n=null!==(o=e.previousElementSibling?.value)&&void 0!==o?o:null;e.checked=t.includes(n)})),d.init(n),d.autoFillData(),await d.submit()||(r?L.show({modal:s}):b.showOverlay(s))))}}const S=p,w={intentField:"heavy-intent",intentDataField:"heavy-intent-data",intentFetchCounter:"heavy-intent-fetch-counter",init(){w.setIntentListeners(),document.addEventListener("heavy:logged-in",(()=>{w.runIntent()}))},setIntentListeners(){document.querySelectorAll("[data-intent]").forEach((e=>{e.addEventListener("click",(()=>{let t=e.dataset.intent;var o;t=t.replace(/[^a-z-]/g,""),t&&(w.setIntent(t),w.setIntentData(null!==(o=w.getIntentObject(t)?.getState?.())&&void 0!==o?o:""))}))}))},runIntent(){var e;const t=null!==(e=w.getIntent())&&void 0!==e?e:"";if(!t)return;const o=w.getIntentData();w.getIntentObject(t)?.run(o),setTimeout((()=>{l({eventName:"login",eventMethod:t})}),0),w.clearIntent()},clearIntent(){localStorage.removeItem(w.intentField),localStorage.removeItem(w.intentDataField),localStorage.removeItem(w.intentFetchCounter)},getIntentObject(e){switch(e){case"comment":return new t;case"subscribe":return new S;case"contest":return new o;case"login":case"adfree":break;default:console.error("Unknown intent:",e)}},isPending:e=>w.getIntent()===e.slug,getIntent(){var e;const t=null!==(e=localStorage.getItem(w.intentField))&&void 0!==e?e:"",o=parseInt(localStorage.getItem(w.intentFetchCounter)||"0",10)+1;return localStorage.setItem(w.intentFetchCounter,o),o>6&&w.clearIntent(),t},setIntent(e){localStorage.setItem(w.intentField,e)},getIntentData(){var e;return JSON.parse(null!==(e=localStorage.getItem(w.intentDataField))&&void 0!==e?e:"{}")},setIntentData(e){localStorage.setItem(w.intentDataField,JSON.stringify(e))}},E=w,I={triggerSelector:'[data-overlay-target^="subscribe-form"]',modalsSelector:".c-subscribe-form",overlaySelector:".c-subscribe-form__overlay",init(){if(!document.querySelector(I.modalsSelector))return;const e=window.location.hash.substring(1);if(e.startsWith("subscribe-form")&&!E.isPending(S)){const t=document.getElementById(e)||document.querySelector(I.modalsSelector);I.show({modal:t})}u(I.triggerSelector,"click",I.handleTriggerClick),setTimeout((()=>{const e=document.querySelectorAll(I.triggerSelector);requestAnimationFrame((()=>{e.forEach((e=>{e.classList.add("is-enabled")}))}))}),0)},handleTriggerClick(e){const t=e.target.closest(".c-subscribe-modal__trigger");if(!t)return;const o=t.getAttribute("data-overlay-target")||"subscribe-form",n={modal:document.getElementById(o)||document.querySelector(I.modalsSelector),event:e};I.show(n)},async show({modal:e,event:t=null}){const o=this;if(!e)return;document.documentElement.classList.add("is-critical-overlay-open"),e.classList.add("is-active"),o.modal=e,o.overlay=e.querySelector(I.overlaySelector),o.closeTrigger=e.querySelector(".l-drawer__close"),o.formSubmitButton=e.querySelector(".c-subscribe-form__submit"),o.attachEvents(),await m(),window.history.replaceState({overlay:!0},"",window.location.pathname+"#"+e.id);const n=new CustomEvent("heavy:modalOpen",{detail:{isModalOpen:!0,modal:e}});document.dispatchEvent(n),setTimeout((()=>{l({eventName:"overlay_open",eventId:"subscribe-form",eventMethod:t?"click":"auto"})}),0)},async close(){const e=this;e.modal&&(document.documentElement.classList.remove("is-critical-overlay-open"),e.modal.classList.remove("is-active"),await m(),e.countDown&&(clearTimeout(e.countDown),e.countDown=null),e.detachEvents(),window.history.replaceState({overlay:!1},"",window.location.pathname))},attachEvents(){const e=this;e.boundClose=e.close.bind(e),e.boundKeyUp=function(t){"Escape"===t.key&&e.close()},e.closeTrigger.addEventListener("click",e.boundClose),e.overlay.addEventListener("click",e.boundClose),document.addEventListener("heavy:subscribed",e.initCountDown.bind(e)),document.addEventListener("keyup",e.boundKeyUp)},detachEvents(){const e=this;e.closeTrigger.removeEventListener("click",e.boundClose),e.overlay.removeEventListener("click",e.boundClose),document.removeEventListener("keyup",e.boundKeyUp)},attachTriggerEvents(e){const t=this,o=e.detail.overlay.querySelector(".c-subscribe-modal__trigger");o&&o.addEventListener("click",(()=>t.show()))},initCountDown(){const e=this;e.countDown=setTimeout((()=>e.close()),3e3)},filledInForm(){let e=!1,t=!1;return this.formCheckboxes.forEach((e=>{e.checked&&(t=!0)})),t&&""!==this.emailInput.value&&(e=!0),e},onFillForm(){const e=this;e.emailInput.addEventListener("input",(()=>{e.formSubmitButton.disabled=!e.filledInForm()})),e.formCheckboxes.forEach((t=>{t.addEventListener("change",(()=>{e.formSubmitButton.disabled=!e.filledInForm()}))}))}},L=I;async function _(){setTimeout((()=>L.init()),0)}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",_):_()})();