1import{B as t}from"./BaseElement.wji90fuE.min.js";import{i as e,r as i}from"./helpers.BN2Mmr8t.min.js";import{H as o}from"./HTMLUpdateUtility.Y324tWjQ.min.js";import{t as r,x as s}from"./vendor-lit.2u3dzq2T.min.js";import"./filter-state.CHhZ4ouW.min.js";import"./WithApiClient.B8AOHZZP.min.js";import"./fetchWithCache.BJ12kVQ7.min.js";import"./vendor.D2HIaoTS.min.js";import"./firstFocusableElement.CXP_yyKj.min.js";Object.getOwnPropertyDescriptor;const n='[sub-section-id="product-grid-container"] ul';let a=class extends t{constructor(){super(...arguments),this.html=new o(this),this.activated=!1,this.loading=!1,this.loadError=!1,this.exhausted=!1,this.windowMode=!1,this.currentPage=1,this.replayToken=0,this.sectionId="",this.total=0,this.moreLabel="",this.loadingLabel="",this.showingTemplate="{shown}/{total}",this.loadMoreLink=null,this.onPopState=()=>{this.activated&&(this.windowMode?this.reloadPage():this.replayTo(this.readUrlPage()))},this.onFallback=t=>{const e=t.detail;(null==e?void 0:e.sectionId)&&e.sectionId!==this.sectionId||this.activate()},this.onClick=t=>{t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||0!==t.button||(t.preventDefault(),this.loadNext())}}createRenderRoot(){return document.createElement("div")}render(){return s``}connectedCallback(){var t;super.connectedCallback(),this.sectionId=this.getAttribute("section-id")??"",this.total=Number(this.dataset.total??"")||0,this.showingTemplate=this.dataset.showingTemplate||this.showingTemplate,this.loadingLabel=this.dataset.loadingLabel??"",this.currentPage=this.readUrlPage(),this.loadMoreLink=this.querySelector("[data-lm-load-more]"),this.loadMoreLink&&(this.moreLabel=(null==(t=this.loadMoreLink.textContent)?void 0:t.trim())??"",this.loadMoreLink.addEventListener("click",this.onClick)),document.addEventListener("fhr:fallback",this.onFallback),window.addEventListener("popstate",this.onPopState),e(),this.closest("[hidden]")||this.activate()}disconnectedCallback(){var t;document.removeEventListener("fhr:fallback",this.onFallback),window.removeEventListener("popstate",this.onPopState),null==(t=this.loadMoreLink)||t.removeEventListener("click",this.onClick),super.disconnectedCallback()}reloadPage(){window.location.reload()}activate(){if(this.activated)return;if(this.activated=!0,!this.gridUl)return;const t=this.readUrlPage();if(t>10)return this.windowMode=!0,this.currentPage=t,this.updateFooter(),void this.restoreScroll();this.hideNumberedPagination(),t>1?this.replayTo(t):(this.currentPage=1,this.updateFooter(),this.restoreScroll())}get sectionRoot(){return this.closest("[data-section-id]")??document}get gridUl(){return this.sectionRoot.querySelector(n)}hideNumberedPagination(){this.sectionRoot.querySelectorAll("[data-lm-pagination]").forEach(t=>{t.hidden=!0})}shownCount(){var t;return(null==(t=this.gridUl)?void 0:t.querySelectorAll(":scope > li:not([data-ingrid])").length)??0}readUrlPage(){const t=Number(new URLSearchParams(window.location.search).get("page"));return Number.isFinite(t)&&t>1?Math.floor(t):1}async loadNext(){if(this.loading||this.exhausted)return;if(this.total&&this.shownCount()>=this.total)return;this.loading=!0,this.loadError=!1,this.updateFooter();const t=await this.fetchAndAppend(this.currentPage+1);t<0?this.loadError=!0:0===t?this.exhausted=!0:(this.currentPage+=1,this.writeUrl(this.currentPage)),this.loading=!1,this.updateFooter(),this.manageFocus()}async replayTo(t){const e=this.gridUl;if(!e)return void this.updateFooter();const i=++this.replayToken,o=Math.min(t,10);
1this.windowMode=!1,this.exhausted=!1,this.loading=!0,this.updateFooter(),e.replaceChildren(),this.currentPage=0;for(let r=1;r<=o;r++){const t=await this.fetchAndAppend(r);if(i!==this.replayToken)return;if(t<=0)break;this.currentPage=r}this.loading=!1,this.updateFooter(),this.restoreScroll()}restoreScroll(){const t=i();null!=t&&requestAnimationFrame(()=>window.scrollTo(0,t))}async fetchAndAppend(t){try{const e=(await this.html.fetchSections({sectionIds:[this.sectionId],params:{page:String(t)},includeExistingParams:!0,withCache:!0}))[this.sectionId],i=this.gridUl;if("string"!=typeof e||!i)return-1;const o=(new DOMParser).parseFromString(e,"text/html").querySelectorAll(`${n} > li`);return o.forEach(t=>i.appendChild(document.importNode(t,!0))),o.length}catch{return-1}}writeUrl(t){const e=new URL(window.location.href);t<=1?e.searchParams.delete("page"):e.searchParams.set("page",String(t)),history.pushState(history.state,"",e.toString())}syncHref(){var t;if(!(null==(t=this.loadMoreLink)?void 0:t.hasAttribute("href")))return;const e=new URL(window.location.href);e.searchParams.set("page",String(this.currentPage+1)),this.loadMoreLink.setAttribute("href",`${e.pathname}${e.search}`)}interpolate(t,e){let i=t;for(const[o,r]of Object.entries(e))i=i.replace(new RegExp(`\\{${o}\\}`,"g"),String(r));return i}manageFocus(){requestAnimationFrame(()=>{var t;!this.loadMoreLink||this.loadMoreLink.hidden?null==(t=this.querySelector("[data-lm-end]"))||t.focus({preventScroll:!0}):this.loadMoreLink.focus({preventScroll:!0})})}updateFooter(){if(!this.gridUl)return;const t=this.querySelector("[data-lm-footer]");t&&(t.hidden=!1);const e=this.shownCount(),i=!this.exhausted&&e<(this.total||e),o=this.exhausted&&!this.windowMode?e:this.total||e,r=this.querySelector("[data-lm-showing]");r&&(r.hidden=this.windowMode,r.textContent=this.windowMode?"":this.interpolate(this.showingTemplate,{shown:e,total:o}));const s=this.querySelector("[data-lm-error]");if(s&&(s.hidden=!this.loadError),this.loadMoreLink){this.loadMoreLink.hidden=!i;const t=this.loading?"true":"false";this.loadMoreLink.setAttribute("aria-busy",t),this.loadMoreLink.setAttribute("aria-disabled",t),this.loadMoreLink.textContent=this.loading?this.loadingLabel:this.moreLabel,i&&this.syncHref()}const n=this.querySelector("[data-lm-end]");n&&(n.hidden=i)}};a=((t,e)=>{for(var i,o=e,r=t.length-1;r>=0;r--)(i=t[r])&&(o=i(o)||o);return o}
1)([r("collection-load-more")],a);export{a as CollectionLoadMore};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.