/*!
 * Custom elements for Nanopore-Digital Web applications
 */
import{r as t,c as s,g as e,a as i}from"./index-BM3Om9WE.js";import{h}from"./renderer-DpNDfhNy.js";import{W as a,S as n}from"./algolia-data-Kh0vPn3V.js";const d=class{constructor(e){t(this,e),this.nanoPageChanged=s(this,"nanoPageChanged",7),this.nanoTplUpdated=s(this,"nanoTplUpdated",7)}get el(){return e(this)}resultTpl;resultTplSlot;startTpl;startTplSlot;endTpl;endTplSlot;outputSlot;outputEle;outputTo;startOutputSlot;endOutputSlot;io;infiniteScrollBar;append=!1;shouldClear=!0;currHitNum=0;showResults=!1;tplRenderFn;results=null;indexResults=null;resultsPage=0;changeEvent=n.Init;facets;isLoading=!0;infiniteScroll=!1;appendPages=!1;nanoPageChanged;nanoTplUpdated;addContentIndex(){this.shouldPageClear(),(this.shouldClear||0===this.resultsPage)&&(this.currHitNum=0),this.indexResults&&this.indexResults.results&&this.indexResults.results.map((t=>{t._uIndex=this.currHitNum++}))}resultsChange(){this.shouldPageClear(),this.updateResultContent(),this.infiniteScrollChange()}headerFooterChange(){this.updateStartEndContent()}appendChange(){this.append=!!this.infiniteScroll||this.appendPages}infiniteScrollChange(){this.append=!!this.infiniteScroll||this.appendPages,this.infiniteScroll?this.attachIO():this.detachIO()}handlePageChage(){this.infiniteScroll?this.attachIO():this.detachIO()}handleLoading(){this.isLoading||this.infiniteScrollChange()}shouldPageClear(){this.shouldClear=this.changeEvent!==n.Page||!this.append}nextPage(){this.shouldClear=!this.append,this.nanoPageChanged.emit({page:this.resultsPage+1})}attachIO(){this.infiniteScrollBar&&this.infiniteScroll&&!this.io&&"undefined"!=typeof window&&window.IntersectionObserver&&(this.io=new window.IntersectionObserver((async t=>{(t[0].isIntersecting||t[1]&&t[1].isIntersecting)&&(this.nextPage(),this.detachIO())}),{document,rootMargin:"100px",threshold:1}),this.io.observe(this.infiniteScrollBar))}detachIO(){this.io&&(this.io.disconnect(),this.io=null)}updateStartEndContent(){this.startTpl&&this.startOutputSlot&&(this.startOutputSlot.innerHTML=this.tplRenderFn(this.startTpl,this.indexResults)),this.endOutputSlot&&this.endTpl&&(this.endOutputSlot.innerHTML=this.tplRenderFn(this.endTpl,this.indexResults)),this.nanoTplUpdated.emit(this.el)}updateResultContent(){if(this.outputTo=this.outputSlot||this.outputEle,!this.resultTpl||!this.indexResults)return;if(this.shouldClear&&(this.outputTo.innerHTML=""),!this.tplRenderFn)return;const t=document.createElement("div");t.innerHTML=this.tplRenderFn(this.resultTpl,this.indexResults),Array.from(t.children).forEach((t=>{this.outputTo.appendChild(t)})),this.shouldClear=!0,this.nanoTplUpdated.emit(this.el)}connectedCallback(){this.startTplSlot=this.el.querySelector('[slot="start-template"]'),this.startOutputSlot=this.el.querySelector('[slot="start-output"]'),this.startTplSlot&&(this.startTpl=this.startTplSlot.innerHTML,this.startTpl=this.startTpl.replace(/=&gt;/gm,"=>")),this.resultTplSlot=this.el.querySelector('[slot="result-template"]'),this.outputSlot=this.el.querySelector('[slot="result-output"]'),this.resultTplSlot&&(this.resultTpl=this.resultTplSlot.innerHTML,this.resultTpl=this.resultTpl.replace(/=&gt;/gm,"=>")),this.endTplSlot=this.el.querySelector('[slot="end-template"]'),this.endOutputSlot=this.el.querySelector('[slot="end-output"]'),this.endTplSlot&&(this.endTpl=this.endTplSlot.innerHTML,this.endTpl=this.endTpl.replace(/=&gt;/gm,"=>")),this.indexResults&&(this.addContentIndex(),this.updateResultContent())}componentDidLoad(){this.updateStartEndContent()}disconnectedCallback(){this.io&&(this.io.disconnect(),this.io=void 0)}render(){return h(i,{key:"857784ead2b9536559ef2220bff26d508061781c",class:{"show-results":this.showResults,"nano-results":!0}},h("div",{key:"be165b02c4ec5d2358e15dadfd4695fd5901f0b0",class:"default"},h("slot",{key:"1ab64bb71c75531e8f6b0c65833de7d2dc1ee0ca"})),h("div",{key:"cee981cead8b921e29fd4223e4985c3615e0e063",ref:t=>this.outputEle=t},h("slot",{key:"cff96070ca2acf18f7b8165444b28f433ca3601d",name:"start-output"}),h("slot",{key:"76833dd55d415baf083527ed5580049f90c36b40",name:"result-output"}),h("div",{key:"dac7a9081d1a65b4e17dec60044467e17575568e",ref:t=>this.infiniteScrollBar=t}),h("slot",{key:"07c82d60a58c11bcc50807ab95d63cf3fd59d768",name:"end-output"})))}static get watchers(){return{results:["addContentIndex","resultsChange"],tplRenderFn:["resultsChange"],facets:["headerFooterChange"],appendPages:["appendChange"],infiniteScroll:["infiniteScrollChange"],resultsPage:["handlePageChage"],isLoading:["handleLoading"]}}};a(d,["indexResults","results","tplRenderFn","resultsPage","changeEvent","facets","isLoading"]);export{d as nano_algolia_results}