import"./unmute.OS053vMb.js";import{d as w,f as u,k as W,l as b,q as y,t as j,m as I,p as M}from"./app.QJ7UH14D.js";const H=200,T=-1,N=1,p=2,U=(s,o)=>{const e=s.scrollWidth,t=s.offsetWidth;return e>=t+o/p},_=(s,o,e,t)=>{u.mutate(()=>{o.style.display=t?"block":"none",e.style.display=t?"block":"none",s.forEach(a=>{a instanceof HTMLElement&&(a.style.display=t?"block":"none")})})},h=(s,o,e,t)=>{const a=s.scrollLeft,c=s.offsetWidth;if(o!==void 0&&u.mutate(()=>{o.style.fill=a===0?"#666":"#FFF",o.style.cursor=a===0?"auto":"pointer"}),e!==void 0&&t===void 0&&(t=s.scrollWidth),e!==void 0&&t!==void 0){const n=t-c;u.mutate(()=>{e.style.fill=a===n?"#666":"#FFF",e.style.cursor=a===n?"auto":"pointer"})}},S=(s,o,e,t)=>{let a=0;const c=15,n=Math.floor(o/c),i=n*c,l=Math.round(o-i),r=n+l;let d=!0;const f=()=>{d?(s.scrollLeft+=e*r,a+=r,d=!1):(s.scrollLeft+=e*n,a+=n),a{f()})},E=[],k=[],D=(s,o,e,t)=>{E[t]&&o.removeEventListener("click",E[t]),k[t]&&s.removeEventListener("click",k[t]);const a=e.scrollWidth;e.addEventListener("scroll",()=>{h(e,s,o,a)},{passive:!0});const c=e.children.length,i=a/c*p,l=()=>{S(e,i,N,o),h(e,s,o,a)},r=()=>{S(e,i,T,s),h(e,s,o,a)};E[t]=l,k[t]=r,o.addEventListener("click",l),s.addEventListener("click",r),h(e,s,o)},O=()=>{u.measure(()=>{const s=document.querySelectorAll(".listing__arrow--left");let o;s.forEach((t,a)=>{const c=t.parentElement;if(c===null)return;const n=c.querySelector(".listing__arrow--right");if(n===null)return;const i=c.querySelector(".listing__list");if(i===null)return;const l=i.querySelector(".listing__item");if(l===null)return;const r=l.nextElementSibling;if(r===null)return;const d=r.querySelector(".listing__image-layout");if(d===null)return;const f=c.querySelectorAll(".listing__fade"),m=r.offsetWidth;if(U(i,m))_(f,t,n,!0);else{_(f,t,n,!1);return}D(t,n,i,a);const g=d.offsetHeight;o=g+1;const x=t.offsetHeight,v=g/p-x/p;u.mutate(()=>{t.style.marginTop=v+"px",n.style.marginTop=v+"px"})}),document.querySelectorAll(".listing__fade").forEach(t=>{u.mutate(()=>{t.style.height=o+"px"})})})},F=w(O,H),z=(()=>{const s=[];let e=!1;function t(){e||(e=!0,window.requestAnimationFrame?window.requestAnimationFrame(a):setTimeout(a,66))}function a(){s.forEach(n=>{n()}),e=!1}function c(n){n&&s.push(n)}return{add:n=>{s.length||window.addEventListener("resize",t),c(n)}}})(),{maybe:A,sequence:q}=j.Maybe,P=()=>{q({term:b("quickSearch",document),resultsPane:b("listing__quicksearch-results",document)}).fmap(o=>Object.assign({},o,{resultsPane:o.resultsPane,term:o.term})).caseOf({nothing:()=>console.warn("%c FTE ","background: #9306F9; color: #ffffff","Not running load more"),just:({term:o,resultsPane:e})=>{const t=o.value;if(t.length>3){const c=`/data/search?searchTerm=${t}&articleType=reviews&format=instant`;fetch(c).then(n=>n.text()).then(n=>{const i=JSON.parse(n);if(i.length>0){let l=i.reduce((r,d)=>r+`
  • ${d.articleName}
  • `,"");l=``,u.mutate(()=>{e.innerHTML=l,e.style.display="block"})}else u.mutate(()=>{e.style.display="none"})}).catch(n=>console.error("%c FTE ","background: #9306F9; color: #ffffff","Quick Search Ajax Error",n))}else u.mutate(()=>{e.style.display="none"})}})},L=(s,o)=>{const e=Number(s.getAttribute("data-total-count"));document.getElementsByClassName("listing__item").length>=e&&u.mutate(()=>{o.remove()})},R=s=>{u.measure(()=>{b("quickSearch",document).fmap(c=>c).caseOf({nothing:()=>console.warn("%c FTE ","background: #9306F9; color: #ffffff","Search element doesn't exist"),just:c=>{c.onkeyup=()=>P()}});const e=(c,n,i)=>l=>{u.mutate(()=>{c.appendChild(document.createRange().createContextualFragment(l)),s.formatRelativeDates(),L(n,i)})},t=(c,n)=>new Promise((i,l)=>{const r=A(c.getAttribute("data-next"));I(".listing__item time",n).fmap(f=>f[f.length-1]).fmap(f=>f.getAttribute("datetime")).fmap(M).chain(f=>r.fmap(m=>m.split("/")).fmap(m=>{const g=new Date(f);return m.pop(),m.push(Math.floor(g.getTime()/1e3).toString()),m.join("/")})).caseOf({nothing:l,just:i})});q({additionArea:y("#main .listing[data-next] .listing__list",document),element:y("#main .listing[data-next]",document),button:y("#main .listing[data-next] .load-more",document)}).fmap(c=>Object.assign({},c,{button:c.button})).caseOf({nothing:()=>console.warn("%c FTE ","background: #9306F9; color: #ffffff","Not running load more"),just:({additionArea:c,element:n,button:i})=>{const l=e(c,n,i);L(n,i),i.onclick=()=>t(n,c).then(fetch).then(r=>r.status===200?r.text():Promise.reject(new Error)).then(l).catch(console.error)}})})};W().then(R).then(F).then(()=>z.add(F)).catch(s=>console.error("%c FTE ","background: #9306F9; color: #ffffff","Listing.ts init error",s));