/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/searchkit@4.16.0/dist/umd/index.global.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var SearchkitDefault=(()=>{var e,t,r=Object.create,i=Object.defineProperty,n=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,s=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,u=(e,t,r,s)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let u of a(t))!o.call(e,u)&&u!==r&&i(e,u,{get:()=>t[u],enumerable:!(s=n(t,u))||s.enumerable});return e},l=(e=(e,t)=>{var r=function(e){return!(!(t=e)||"object"!=typeof t||function(e){var t=Object.prototype.toString.call(e);return"[object RegExp]"===t||"[object Date]"===t||function(e){return e.$$typeof===i}(e)}(e));var t},i="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function n(e,t){return!1!==t.clone&&t.isMergeableObject(e)?l(function(e){return Array.isArray(e)?[]:{}}(e),e,t):e}function a(e,t,r){return e.concat(t).map((function(e){return n(e,r)}))}function s(e){return Object.keys(e).concat(function(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter((function(t){return Object.propertyIsEnumerable.call(e,t)})):[]}(e))}function o(e,t){try{return t in e}catch{return!1}}function u(e,t,r){var i={};return r.isMergeableObject(e)&&s(e).forEach((function(t){i[t]=n(e[t],r)})),s(t).forEach((function(a){(function(e,t){return o(e,t)&&!(Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))})(e,a)||(o(e,a)&&r.isMergeableObject(t[a])?i[a]=function(e,t){if(!t.customMerge)return l;var r=t.customMerge(e);return"function"==typeof r?r:l}(a,r)(e[a],t[a],r):i[a]=n(t[a],r))})),i}function l(e,t,i){(i=i||{}).arrayMerge=i.arrayMerge||a,i.isMergeableObject=i.isMergeableObject||r,i.cloneUnlessOtherwiseSpecified=n;var s=Array.isArray(t);return s===Array.isArray(e)?s?i.arrayMerge(e,t,i):u(e,t,i):n(t,i)}l.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce((function(e,r){return l(e,r,t)}),{})};var c=l;t.exports=c},()=>(t||e((t={exports:{}}).exports,t),t.exports)),c={};((e,t)=>{for(var r in t)i(e,r,{get:t[r],enumerable:!0})})(c,{ESTransporter:()=>U,MatchFilter:()=>h,TermFilter:()=>d,default:()=>Z});var f=((e,t,n)=>(n=null!=e?r(s(e)):{},u(!t&&e&&e.__esModule?n:i(n,"default",{value:e,enumerable:!0}),e)))(l()),d=(e,t)=>({term:{[e]:t}}),h=(e,t)=>({match:{[e]:t}}),g=(e,t)=>e.find((e=>"string"==typeof e?e===t:e.attribute===t))||null,p=e=>"string"!=typeof e&&!!e.nestedPath,y=e=>e.reduce(((e,t)=>[...e,JSON.stringify({index:t.indexName}),"\n",JSON.stringify(t.body),"\n"]),[]).join(""),m=(e,t)=>{let{params:r={}}=e,{numericFilters:i}=r;return Array.isArray(i)?i.reduce(((e,r)=>{let i,n,a,s,o="",u=r.match(/([\w\.\_\-]+)\s*(\=|\!\=|\>|\>\=|\<|\<\=)\s*(-?(?:\d+(?:\.\d*)?|\.\d+))/);if(u)[i,n,a,s]=u;else{if(u=r.match(/([\w\.\_\-]+):\s*(-?(?:\d+(?:\.\d*)?|\.\d+))\s*([Tt][Oo])\s*(-?(?:\d+(?:\.\d*)?|\.\d+))/),!u)throw new Error(`Numeric filter "${r}" could not be parsed. It should either be in the format "attributeName operator operand" or "attributeName: lowerBound TO upperBound"`);[i,n,s,a,o]=u}let l=b(t.facet_attributes||[],t.filter_attributes||[])[n],c=(e,t,r)=>"="===t?{term:{[e]:r}}:"!="===t?{bool:{must_not:{term:{[e]:r}}}}:">"===t?{range:{[e]:{gt:r}}}:">="===t?{range:{[e]:{gte:r}}}:"<"===t?{range:{[e]:{lt:r}}}:"<="===t?{range:{[e]:{lte:r}}}:"TO"===t.toUpperCase()?{range:{[e]:{gte:r,lte:o}}}:void 0,f=[];if(l.nestedPath){let t=e.find((e=>e.nested.path===l.nestedPath));t?t.nested.query.bool.filter.push(c(l.nestedPath+"."+l.field,a,s)):f.push({nested:{path:l.nestedPath,inner_hits:{},query:{bool:{filter:[c(l.nestedPath+"."+l.field,a,s)]}}}})}else f.push(c(l.field,a,s));return[...e,...f]}),[]):[]},b=(e,t)=>[...t,...e].reduce(((e,t)=>{let r="string"==typeof t?{attribute:t,field:t,type:"string"}:t;return{...e,[r.attribute]:r}}),{}),_=(e,t)=>{let{params:r={}}=e,{facetFilters:i}=r;if(!Array.isArray(i))return[];let n=b(t.facet_attributes||[],t.filter_attributes||[]);return i.reduce(((e,t)=>{if(Array.isArray(t))return[...e,{bool:{should:t.reduce(((e,t)=>{let[r,i]=t.split(/:(.*)/),a=n[r];if(!a)throw new Error(`Facet "${r}" not found in configuration. Add configuration to either facet_attributes or filter_attributes.`);let s=a.field,o="filterQuery"in a&&a.filterQuery?a.filterQuery:d;if(p(a)){let t=e.find((e=>e.nested&&e.nested.path===a.nestedPath));return t?(t.nested.query.bool.should.push(o(`${a.nestedPath}.${a.field}`,i)),e):[...e,{nested:{inner_hits:{},path:a.nestedPath,query:{bool:{should:[o(`${a.nestedPath}.${a.field}`,i)]}}}}]}return[...e,o(s,i)]}),[])}}];if("string"==typeof t){let[r,i]=t.split(/:(.*)/),a=n[r];if(!a)throw new Error(`Facet "${r}" not found in configuration. Add configuration to either facet_attributes or filter_attributes.`);let s="filterQuery"in a&&a.filterQuery?a.filterQuery:d;if(p(a)&&a.nestedPath){let t=e.find((e=>e.nested&&e.nested.path===a.nestedPath+"."));return t?(t.nested.query.bool.should.push(s(`${a.nestedPath}.${a.field}`,i)),e):[...e,{nested:{inner_hits:{},path:a.nestedPath,query:{bool:{should:[s(`${a.nestedPath}.${a.field}`,i)]}}}}]}return[...e,s(a.field,i)]}}),[])},v=(e=[],t=[],r)=>{let i=b(e,t);return r.replace(/([\w\.\-]+)\:/gi,((e,t)=>{if(!i[t])throw new Error(`Attribute "${t}" is not defined as an attribute in the facet or filter search settings`);if(i[t].nestedPath)throw new Error(`Attribute "${t}" is a nested field and cannot be used as a filter. Nested fields are supported in facetFilers or numericFilters.`);return i[t].field+":"}))},w=(e,t)=>{let{params:r={}}=e,{filters:i}=r;return i&&""!==i?[{query_string:{query:v(t.facet_attributes,t.filter_attributes,i)}}]:[]},A=(e,t)=>{if(!t.geo_attribute)return[];let{params:r={}}=e,{aroundLatLng:i,aroundRadius:n,insideBoundingBox:a}=r;if(a)return[O(a,t.geo_attribute)];if(i){let e=i.split(",");return[{geo_distance:{distance:n||"1000m",[t.geo_attribute]:{lat:e[0],lon:e[1]}}}]}return[]};function O(e,t){let r=(e,r,i,n)=>({geo_bounding_box:{[t]:{top_right:{lat:e,lon:r},bottom_left:{lat:i,lon:n}}}});if("string"==typeof e){let[t,i,n,a]=e.split(",");return r(parseFloat(t),parseFloat(i),parseFloat(n),parseFloat(a))}if(Array.isArray(e))return{bool:{should:e.map((e=>{let[t,i,n,a]=e;return r(parseFloat(t),parseFloat(i),parseFloat(n),parseFloat(a))}))}}}function P(e,t){if(t.sorting&&Object.keys(t.sorting).length>0){let r=Object.keys(t.sorting).find((t=>{if(e.indexName.endsWith(t))return!0}));if(!r&&!t.sorting.default)return{};let i=r?t.sorting[r]:t.sorting.default,n=e=>{let t=e.nestedPath?`${e.nestedPath}.${e.field}`:e.field;if(e.nestedPath){let r={order:e.order,nested:{path:e.nestedPath}};return e.mode&&(r.mode=e.mode),{[t]:r}}let r=e.order;return e.mode?{[t]:{order:e.order,mode:e.mode}}:{[t]:r}};return{sort:Array.isArray(i)?i.map(n):n(i)}}return{}}function k(e,t){if(t.sorting&&Object.keys(t.sorting).length>0){let r=Object.keys(t.sorting).find((t=>{if(e.endsWith(t))return!0}));if(r)return e.replace(r,"")}return e}var q=e=>{let t=e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");return t=t.split("").map((e=>/[a-z]/.test(e)?`[${e}${e.toUpperCase()}]`:e)).join(""),t=`${t}.*`,e.length>2&&(t=`([a-zA-Z]+ )+?${t}`),t},x=(e,t,r)=>({terms:{field:e,size:t,...r&&r.length>0?{include:q(r)}:{}}}),S=(e,t,r)=>{let i={},n="string"!=typeof e&&"facetQuery"in e?e.facetQuery:x,a=(a,s)=>("string"==typeof e||"string"===e.type?i={[a]:n(s,t,r)}:"numeric"===e.type&&(i={[a+"$_stats"]:{stats:{field:s}},[a+"$_entries"]:n(s,t,r)}),i);return"string"==typeof e?a(e,e):p(e)?{[`${e.nestedPath}.`]:{nested:{path:e.nestedPath},aggs:a(e.attribute,`${e.nestedPath}.${e.field}`)}}:a(e.attribute,e.field)},$=(e,t,r)=>{let{params:i={},type:n}=e,{facets:a,maxValuesPerFacet:s,facetName:o,facetQuery:u}=i,l=s||10,c=t.facet_attributes||[];if(o){let e=g(c,o);return e?S(e,l,u):null}if(Array.isArray(a)){let e=t.facet_attributes||[];return r.facetAttributesOrder&&(e=r.facetAttributesOrder.map((e=>g(t.facet_attributes||[],e))).filter((e=>null!==e))),("*"===a[0]?e:a.map((e=>g(t.facet_attributes||[],e))).filter((e=>null!==e))).reduce(((e,t)=>(0,f.default)(e,S(t,l,""))),{})||{}}if("string"==typeof a){let e=g(t.facet_attributes||[],a);return e?S(e,l,""):{}}};function E(e,t){return t.touched?{function_score:{query:{pinned:{ids:t.pinnedDocs,organic:e}},functions:t.boostFunctions}}:e}var j=(e,t,r,i)=>{var n,a,s;let o=r.query,u=t.search_attributes,l=t.fuzziness??"AUTO:4,8",c=[..._(e,t),...m(e,t),...w(e,t),...A(e,t),...(null==(n=null==i?void 0:i.getBaseFilters)?void 0:n.call(i))||[],...r.baseFilters],f="string"==typeof o&&""!==o?null!=i&&i.getQuery?i.getQuery(o,u,t):function(e,t,r="AUTO:4,8"){let i=e=>t.map((t=>"string"==typeof t?t:`${t.field}^${(t.weight||1)*e}`));return{bool:{should:[{bool:{should:[{multi_match:{query:e,fields:i(1),fuzziness:r}},{multi_match:{query:e,fields:i(.5),type:"bool_prefix"}}]}},{multi_match:{query:e,type:"phrase",fields:i(2)}}]}}}(o,u,l):{match_all:{}},d="function"==typeof(null==i?void 0:i.getKnnQuery),h=!1===(null==(a=null==i?void 0:i.getQuery)?void 0:a.call(i,o,u,t));(h||d&&""===o)&&(f={match_all:{}});let g={bool:{filter:c,must:r.touched?E(f,r):f}},p=null;if(d&&""!==o&&(p={filter:c,...(null==(s=null==i?void 0:i.getKnnQuery)?void 0:s.call(i,o,u,t))||{}}),""!==o&&h&&d&&p)return{knn:p};let y=F(e);return{query:g,knn:p||void 0,rank:d&&!h&&y>0&&""!==o?{rrf:{window_size:y}}:void 0}},F=e=>{let{params:t={}}=e;return null==t.hitsPerPage?20:t.hitsPerPage},N=(e,t)=>{let{params:r={}}=e,i=F(e);return{size:i,from:(r.page||0)*i}},T=(e,t)=>{let{params:r={}}=e,{attributesToRetrieve:i}=r,n=new Set([...t.result_attributes||[],...t.highlight_attributes||[],...t.geo_attribute?[t.geo_attribute]:[]]),a=Object.keys(t.runtime_mappings||{}).reduce(((e,r)=>{var i;return null!=(i=t.result_attributes)&&i.includes(r)?[r,...e]:e}),[]);return{_source:{includes:Array.from(n)},...a.length>0?{fields:a}:{}}},R=e=>{let t={attribute:e,length:100};if(!e.includes(":"))return t;let r=e.match(/(.+)\:(\d+)/);return r?{attribute:r[1],length:parseInt(r[2])}:t},Q=(e,t)=>{var r,i;let{params:n={}}=e,{attributesToHighlight:a}=n,s=(null==(r=t.highlight_attributes)?void 0:r.reduce(((e,t)=>({...e,[t]:{number_of_fragments:0}})),{}))||{},o=(null==(i=t.snippet_attributes)?void 0:i.reduce(((e,t)=>({...e,[R(t).attribute]:{number_of_fragments:5,fragment_size:R(t).length}})),{}))||{};return 0===Object.keys(s).length&&0===Object.keys(o).length?{}:{highlight:{pre_tags:["<em>"],post_tags:["</em>"],fields:{...s,...o}}}},C=(e,t)=>t.runtime_mappings?{runtime_mappings:t.runtime_mappings}:{};function I(e,t,r,i){return{aggs:$(e,t,r),...j(e,t,r,i),...N(e),...T(e,t),...Q(e,t),...P(e,t),...C(0,t)}}function M(e,t){let r=new RegExp(t,"gi");return e.replace(r,(e=>`<em>${e}</em>`))}function D(e,t="<ais-highlight-0000000000>",r="<ais-highlight-0000000000/>",i=[]){let{_source:n={},highlight:a={}}=e,s={...n,...a},o=i.map((e=>R(e).attribute)),u=Object.keys(s).reduce(((e,i)=>{let s=function(e,t){return t.split(".").reduce(((e,t)=>Array.isArray(e)?e.map((e=>e[t])):e&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0),e)}(n,i),u=a[i]||null;if(!function(e,t){return t.findIndex((t=>{if(t.indexOf("*")<0)return t===e;let r=t.replace(/[.+?^$|\{\}\(\)\[\]\\]/g,"\\$&");return new RegExp(`^${r.replace(/\*/g,".*")}$`).test(e)}))>=0}(i,o))return e;if(Array.isArray(s)&&!u)return{...e,[i]:s.map((e=>({matchLevel:"none",matchedWords:[],value:e.toString()})))};if(Array.isArray(s)&&u&&Array.isArray(u))return{...e,[i]:u.map((e=>({fullyHighlighted:!1,matchLevel:"full",matchedWords:Array.from(e.matchAll(/\<em\>(.*?)\<\/em\>/g)).map((e=>e[1])),value:e.toString().replace(/\<em\>/g,t).replace(/\<\/em\>/g,r)})))};if(!Array.isArray(s)&&u&&Array.isArray(u)||!s&&Array.isArray(u)&&u.length>0){let n=u[0],a={fullyHighlighted:!1,matchLevel:"full",matchedWords:Array.from(n.matchAll(/\<em\>(.*?)\<\/em\>/g)).map((e=>e[1])),value:n.toString().replace(/\<em\>/g,t).replace(/\<\/em\>/g,r)};return{...e,[i]:a}}return{...e,[i]:{matchLevel:"none",matchedWords:[],value:null!=s?s.toString():""}}}),{});return function(e){let t={};for(let r in e){let i=r.split("."),n=t;for(let e=0;e<i.length-1;e++){let t=i[e];n[t]||(n[t]={}),n=n[t]}n[i[i.length-1]]=e[r]}return t}(u)}var z=(e,t,r)=>{let{hits:i}=e,{highlight_attributes:n=[],snippet_attributes:a=[]}=t;return i.hits.map((e=>{var i,s,o,u,l,c;return{objectID:e._id,_index:e._index,_score:e._score,...e._source||{},...e.fields||{},...e.inner_hits?{inner_hits:e.inner_hits}:{},...n.length>0?{_highlightResult:D(e,null==(i=null==r?void 0:r.params)?void 0:i.highlightPreTag,null==(s=null==r?void 0:r.params)?void 0:s.highlightPostTag,n)}:{},...a.length>0?{_snippetResult:D(e,null==(o=null==r?void 0:r.params)?void 0:o.highlightPreTag,null==(u=null==r?void 0:r.params)?void 0:u.highlightPostTag,t.snippet_attributes)}:{},...t.geo_attribute&&null!=(l=e._source)&&l[t.geo_attribute]?{_geoloc:B(null==(c=e._source)?void 0:c[t.geo_attribute])}:{}}}))};function B(e){if("string"==typeof e){let[t,r]=e.split(",").map((e=>parseFloat(e)));return{lat:t,lng:r}}return Array.isArray(e)?{lat:e[0],lng:e[1]}:"object"==typeof e&&"lat"in e&&"lon"in e?{lat:parseFloat(e.lat),lng:parseFloat(e.lon)}:null}var J=e=>e.buckets.reduce(((e,t)=>({...e,[t.key]:t.doc_count})),{}),L=(e,t)=>{if(null==e||!e.aggregations)return{};let r=Object.keys(e.aggregations).reduce(((t,r)=>{let i=(e.aggregations||{})[r];if(r.endsWith(".")){let{doc_count:e,...r}=i;return{...t,...r}}return{...t,[r]:i}}),{});return Object.keys(r).reduce(((e,i)=>{let n=i.split("$")[0],a=((e,t)=>{var r;let i="string"==typeof t?t:t.attribute;return e.includes(i)?"string":(null==(r=e.find((e=>(null==e?void 0:e.attribute)===i)))?void 0:r.type)||"string"})(t.facet_attributes||[],n),s=((e,t)=>e.find((e=>"string"!=typeof e&&e.attribute===t)))(t.facet_attributes||[],n),o=s&&"facetResponse"in s&&(null==s?void 0:s.facetResponse)||J;if("numeric"===a){let t=r[n+"$_stats"],{buckets:i}=r[n+"$_entries"];return{...e,facets:{...e.facets,[n]:o({buckets:i})},facets_stats:{...e.facets_stats,[n]:{min:t.min,avg:t.avg,max:t.max,sum:t.sum}}}}let{buckets:u}=r[n];return{...e,facets:{...e.facets,[n]:o({buckets:u})}}}),{facets:{},facets_stats:{}})},W=(e,t)=>{var r,i;let n=null==(r=e.facet_attributes)?void 0:r.map((e=>"string"==typeof e?e:e.attribute));return{renderingContent:{facetOrdering:{facets:{order:t.facetAttributesOrder||n||[]},values:null==(i=e.facet_attributes)?void 0:i.reduce(((e,r)=>{let i="string"==typeof r?r:r.attribute;return t.facetAttributesOrder&&!t.facetAttributesOrder.includes(i)?e:{...e,[i]:{sortRemainingBy:"count"}}}),{})}}}},H=(e,t,r)=>{let{params:i={}}=t,{hitsPerPage:n=20,page:a=0}=i,{total:s}=e.hits,o="number"==typeof s?s:null==s?void 0:s.value,u=n<=0?0:Math.ceil(("number"==typeof s?s:(null==s?void 0:s.value)||0)/n);return{hitsPerPage:n,processingTimeMS:e.took,nbHits:o,page:a,nbPages:u,query:r.query}};var K=e=>typeof btoa>"u"?Buffer.from(e.username+":"+e.password).toString("base64"):btoa(e.username+":"+e.password);var U=class{constructor(e,t){this.config=e,this.settings=t,this.timeout=t.timeout??3e4}createElasticsearchQueryFromRequest(e){return y(e)}async performNetworkRequest(e){if(void 0===this.config.host&&void 0===this.config.cloud_id)throw new Error("No Elasticsearch host or cloud_id specified. Please provide a host or cloud id in your Searchkit configuration.");let t=this.config.cloud_id?function(e){let t;return t=typeof atob>"u"?Buffer.from(e.split(":")[1],"base64").toString():atob(e.split(":")[1]).split("$"),`https://${t[1]}.${t[0]}`}(this.config.cloud_id):this.config.host,r=new AbortController,i=setTimeout((()=>r.abort()),this.timeout);try{let i=await fetch(`${t}/_msearch`,{headers:{...this.config.apiKey?{authorization:`ApiKey ${this.config.apiKey}`}:{},"content-type":"application/json",...this.config.headers||{},...this.config.auth?{Authorization:"Basic "+K(this.config.auth)}:{}},body:this.createElasticsearchQueryFromRequest(e),method:"POST",signal:r.signal,...this.config.withCredentials?{credentials:"include"}:{}});if(!1===i.ok)throw new Error(`Elasticsearch request failed with status ${i.status}: ${i.statusText}`);return i}catch(e){throw e instanceof Error&&"AbortError"===e.name?new Error(`Elasticsearch request timed out after ${this.timeout}ms`):e}finally{clearTimeout(i)}}async msearch(e){var t,r,i,n,a,s;try{let o=await(await this.performNetworkRequest(e)).json();if(this.settings.debug&&(console.log("Elasticsearch response:"),console.log(JSON.stringify(o))),o.status>=500)throw console.error("Elasticsearch Internal Error: Check your elasticsearch instance to make sure it can recieve requests."),new Error(JSON.stringify(o));if(401===o.status)throw console.error("Cannot connect to Elasticsearch. Check your connection host and auth details (username/password or API Key required). You can also provide a custom Elasticsearch transporter to the API Client. See https://www.searchkit.co/docs/guides/setup-elasticsearch#connecting-with-usernamepassword for more details."),new Error(JSON.stringify(o));if(403===(null==(r=null==(t=o.responses)?void 0:t[0])?void 0:r.status))throw console.error("Auth Error: You do not have permission to access this index. Check you are calling the right index (specified in frontend) and your API Key permissions has access to the index."),new Error(JSON.stringify(o));if(404===o.status||404===(null==(n=null==(i=o.responses)?void 0:i[0])?void 0:n.status))throw console.error("Elasticsearch index not found. Check your index name and make sure it exists."),new Error(JSON.stringify(o));if(400===o.status||400===(null==(s=null==(a=o.responses)?void 0:a[0])?void 0:s.status))throw console.error("Elasticsearch Bad Request.\n\n          1. Check your query and make sure it is valid.\n          2. Check the field mapping. See documentation to make sure you are using text types for searching and keyword fields for faceting\n          3. Turn on debug mode to see the Elasticsearch query and the error response.\n          "),new Error(JSON.stringify(o));return o.responses}catch(e){throw e}}},Y=e=>{if(!e)return[];if("string"==typeof e){let[t,r]=e.split(/:(.*)/);return[{attribute:t,value:r}]}return e.reduce(((e,t)=>{if("string"==typeof t){let[r,i]=t.split(/:(.*)/);return[...e,{attribute:r,value:i}]}return[...e,...Y(t)]}),[])},V=(e,t)=>t.filter((t=>void 0!==t.conditions.find((t=>t.filter((t=>"query"===t.context&&"exact"===t.match_type?t.value===e.query:"query"===t.context&&"contains"===t.match_type?e.query.includes(t.value):"query"===t.context&&"prefix"===t.match_type?e.query.startsWith(t.value):"context"===t.context?t.value.some((t=>e.context.includes(t))):"filterPresent"===t.context&&t.values.every((t=>void 0!==e.filters.find((e=>e.attribute===t.attribute&&e.value===t.value)))))).length===t.length)))),Z=class{constructor(e,t={debug:!1}){this.config=e,this.settings=t,this.transporter="msearch"in e.connection?e.connection:new U(e.connection,t)}async performSearch(e){return this.settings.debug&&(console.log("Performing search with requests:"),console.log("POST /_msearch"),console.log(y(e))),await this.transporter.msearch(e)}async handleInstantSearchRequests(e,t){var r,i;if(!e||!1===Array.isArray(e))throw console.log({instantsearchRequests:e}),new Error("No instantsearch requests provided. Check that the data you are providing from API request is correct. Likely you are not passing the request body correctly, its still a JSON string or the API is not a POST request.");let n=this.config.search_settings.query_rules||[],a=e.map((e=>((e,t,r)=>{var i,n,a;let s={query:(null==(i=t.params)?void 0:i.query)||"",context:(null==(n=t.params)?void 0:n.ruleContexts)||[],filters:Y(null==(a=t.params)?void 0:a.facetFilters)},o=V(s,e||[]);return o.reduce(((e,t)=>(t.actions.map((t=>{e.touched=!0,"PinnedResult"===t.action?e.pinnedDocs.push(...t.documentIds):"QueryRewrite"===t.action?e.query=t.query:"QueryBoost"===t.action?e.boostFunctions.push({filter:{query_string:{query:v(r.facet_attributes,r.filter_attributes,t.query)}},weight:t.weight}):"RenderUserData"===t.action?e.userData.push(JSON.parse(t.userData)):"RenderFacetsOrder"===t.action?e.facetAttributesOrder=t.facetAttributesOrder:"QueryFilter"===t.action&&e.baseFilters.push({query_string:{query:v(r.facet_attributes,r.filter_attributes,t.query)}})})),e)),{ruleIds:o.map((e=>e.id)),pinnedDocs:[],boostFunctions:[],query:s.query,userData:[],facetAttributesOrder:void 0,touched:!1,baseFilters:[]})})(n,e,this.config.search_settings))),s=e.map(((e,r)=>({body:I(e,this.config.search_settings,a[r],t),request:e,indexName:k(e.indexName,this.config.search_settings)})));null!=(r=null==t?void 0:t.hooks)&&r.beforeSearch&&(s=await t.hooks.beforeSearch(s));let o=await this.performSearch(s);null!=(i=null==t?void 0:t.hooks)&&i.afterSearch&&(o=await t.hooks.afterSearch(s,o));try{return{results:o.map(((t,r)=>{var i;return null!=(i=e[r].params)&&i.facetName?((e,t)=>{var r,i,n;let a=e.aggregations||{},s=null==(r=null==t?void 0:t.params)?void 0:r.facetName,o=(null==(i=t.params)?void 0:i.highlightPreTag)||"<ais-highlight-0000000000>",u=(null==(n=t.params)?void 0:n.highlightPostTag)||"<ais-highlight-0000000000/>",l=a[Object.keys(a)[0]];return l&&l[s]&&(l=l[s]),{facetHits:l.buckets.map((e=>({value:e.key,highlighted:M(e.key,t.params.facetQuery||"").replace(/<\em>/g,o).replace(/<\/\em>/g,u),count:e.doc_count}))),exhaustiveFacetsCount:!0,processingTimeMS:e.took}})(t,e[r]):function(e,t,r,i){try{return{appliedRules:i.ruleIds,exhaustiveNbHits:!0,exhaustiveFacetsCount:!0,exhaustiveTypo:!0,exhaustive:{facetsCount:!0,nbHits:!0,typo:!0},...H(e,t,i),...W(r,i),...L(e,r),hits:z(e,r,t),index:t.indexName,params:new URLSearchParams(t.params).toString(),...i.userData.length>0?{userData:i.userData}:{}}}catch{throw new Error("Error transforming Elasticsearch response for index")}}(t,e[r],this.config.search_settings,a[r])}))}}catch(e){throw console.error(e),new Error("Error transforming response. Check the afterSearch hook function is correct. Likely you are not returning the correct response object.")}}};return(e=>u(i({},"__esModule",{value:!0}),e))(c)})(),Searchkit=SearchkitDefault.default;
//# sourceMappingURL=/sm/c523dc24774f08e9364e7f9a2beced071957840e128390ef6621db20a20c09f7.map