"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[348],{17642:(e,t,r)=>{r(58647),r(9635);new class{index=null;constructor(){this.searchFormElement=this.getElementById("search-form"),this.searchFormQueryElement=this.getElementById("search-form-query"),this.searchFormFilterResetElement=this.getElementById("search-form-filter-reset"),this.resultsContainer=this.getElementById("search-results-container"),this.searchFormElement.addEventListener("submit",(e=>{(async()=>{await this.search(this.searchFormQueryElement.value,this.getFilterEntityTypeIds())})(),e.preventDefault(),e.stopPropagation()})),this.searchFormFilterResetElement.addEventListener("click",(()=>{this.resetFilters()})),this.filterEntityTypeHtmlIds=JSON.parse(this.searchFormElement.dataset.bettySearchFormFilterEntityType)}getElementById(e){const t=document.getElementById(e);if(!t)throw new Error(`Cannot find element with ID #${e}`);return t}resetFilters(){this.resetFilterEntityType()}getFilterEntityTypeElements(){return this.searchFormElement.querySelectorAll(".search-form-filter-entity-type input")}getFilterEntityTypeIds(){const e=[];for(const t of this.getFilterEntityTypeElements())t.checked&&e.push(this.filterEntityTypeHtmlIds[t.id]);return e}resetFilterEntityType(){for(const e of this.getFilterEntityTypeElements())e.checked=!0}setSearchEntries(e,t){this.resultsContainer.innerHTML=this.renderResults(e,t)}async getIndex(){if(null===this.index){const e=await fetch(this.searchFormElement.dataset.bettySearchFormIndex);this.index=await e.json()}return this.index}async search(e,t){const r=e.toLowerCase().split(/\s/).filter((e=>e.trim().length)),s=await this.getIndex();r.length?this.setSearchEntries(s,s.index.filter((e=>this.match(r,t,e)))):this.setSearchEntries(s,[])}match(e,t,r){if(!t.includes(r.entityTypeId))return!1;for(const t of e)if(!r.text.includes(t))return!1;return!0}renderResults(e,t){return e.resultsContainerTemplate.replace("{{{ betty-search-results }}}",t.map((e=>this.renderResult(e))).join("")).replace("{{{ betty-search-results-count }}}",t.length)}renderResult(e){return this.index?.resultContainerTemplate.replace("{{{ betty-search-result }}}",e.result)}}}},e=>{e.O(0,[502,109],(()=>{return t=17642,e(e.s=t);var t}));e.O()}]);