import{R as o}from"./Root-rl66e6VO.js";import"./index-D02r7Zsc.js";class f extends o{listThesauri=[];constructor(){super(),this.criteriaArray=!1,this.categories=this.getConfig().simpleSearchCategories}async simpleSearchLocalise(e,t,s,r,i,h=!1){let a=await this.get("ws").simpleSearchLocalise(e,t,s,r,i);return h?(this.set(`search${a.searchId}`,a),a.searchId):{searchId:a.searchId,nbResults:a.nbResults,searchType:t}}async simpleSearch(e,t,s){let r=await this.get("ws").simpleSearch(e,t,s);return{searchId:r.searchId,nbResults:r.nbResults,searchType:t}}async sendSimpleSearch(e,t,s){let r={};var i=[];let h=Object.values(this.categories);for(let a in this.categories)s?i.push(this.simpleSearchLocalise(e,this.categories[a].type,t,JSON.parse(localStorage.getItem("userDefaultLocation")),"")):i.push(this.simpleSearch(e,this.categories[a].type,t));return await Promise.all(i).then(a=>{for(let l in a){let c=a[l];if(c.nbResults!=="0"){let n=h.findIndex(u=>u.type==c.searchType);r[c.searchType]={search:c,label:h[n].label}}}}),Object.keys(r).length?(this.setSimpleSearch(r),r[Object.keys(r)[0]].search.searchId):!1}setSimpleSearch(e){for(let t in e)this.set(`search${e[t].search.searchId}`,e)}async getAdvancedSearchFields(e){if(!this.criteriaArray){this.criteriaArray=[];let t=await this.get("ws").getAdvancedSearchFields(e,!0);for(let s of t)this.getConfig().advancedSearchCriterias.findIndex(i=>parseInt(s.id)==parseInt(i))!==-1&&this.criteriaArray.push(s);return this.criteriaArray}return this.criteriaArray}async advancedSearch(e,t){let s=await this.get("ws").advancedSearch(e,t);return s.nbResults==="0"?!1:(this.set(`search${s.searchId}`,s),s.searchId)}async formalizeCriterias(e,t,s){const r=[11];let i={inter:"and",field:e,operator:t,value:[s],operator_between_multiple_authorities:["or"]},h=await this.getThesauri();return h=h.map(a=>a.thesaurus_id),r.includes(e)&&(i.fieldvar={id_thesaurus:h}),i}async getRecordIdArray(e,t,s,r){let i=[],h=await this.get("ws").searchResults(e,t,s,r);for(let a in h)i.push(h[a].noticeId);return i}noResultModal(e,t){return{show:!0,message:e,title:t}}async getThesauri(){if(this.get("listThesauri"))return this.get("listThesauri");let e=await this.get("ws").listThesauri(this.get("sessionId"));if(e)return this.set("listThesauri",e),e}}export{f as default};
