import{R as b}from"./Root-rl66e6VO.js";import"./index-D02r7Zsc.js";class I extends b{constructor(){super()}recordsLoaded=0;bulletinsLoaded=0;recordsToLoad=20;async getRecordInformations(e,t){var i=[];let r=await this.get("ws").getNotices(e,t);var o={},d=!1;if(r.forEach(s=>{let a=this.getRecordField(s,"463","id");typeof a<"u"&&(o[s.noticeId]=a)}),Object.keys(o).length>0){d=!0;var l=await this.get("ws").getBulletinExpl(e,Object.values(o))}for(let s of r){let a={recordId:s.noticeId,bl:s.noticeContent.header.bl,title:this.getRecordField(s,"200",["a","e"]),subTitle:this.getRecordField(s,"200","e"),serie:this.getRecordField(s,"461",["t","v"]),editor:this.getRecordField(s,"210",["a","b","c","d","9"]),abstract:this.getRecordField(s,"330","a"),collection:this.getRecordField(s,"410",["t","9"]),subCollection:this.getRecordField(s,"411",["t","9"]),image:this.getRecordField(s,"896","a")??s.noticeAdministrative.thumbnail_url,link:this.getRecordField(s,"856","u"),authors:{authors700:this.getRecordField(s,"700",["a","b","c","f","id"]),authors701:this.getRecordField(s,"701",["a","b","c","f","id"]),authors702:this.getRecordField(s,"702",["a","b","c","f","id"])},manifestationInformations:this.getRecordField(s,"215",["a","b","c","d"]),vocabularyIndex:this.getRecordField(s,"610","a"),isbn:this.getRecordField(s,"010",["a","d"]),language:this.formalizeUnimarcLanguage(this.getRecordField(s,"101","a")),itemInformations:s.noticeItems,explNums:s.noticeExplNums,bulletins:s.noticeBulletins,articleBulletin:this.getRecordField(s,"463",["id","d","e","t","v"]),childrenRecords:[],categories:this.getRecordField(s,"606",["a","9"],"all")};const g=[464,462,421,440,430,454,453,423];for(const c of g){let h=this.getRecordField(s,c,["9","t"],"all");if(h)for(let n of h){let u={};for(let f in n[9])n[9][f]&&n[9][f].startsWith("id:")&&(u.id=n[9][f].split("id:")[1]);n.t&&n.t.length>0&&(u.title=n.t.join(" - ")),a.childrenRecords.push(u)}}if(d&&typeof o[s.noticeId]<"u"){let c=l.findIndex(h=>h.bulletin_id==o[s.noticeId]);c!=-1&&(a.itemInformations=l[c].bulletin_items)}a.itemAvailability=this.isAvailable(a.itemInformations),i.push(a)}return i}parseArray(e){let t=[];for(let i in e)t.push(parseInt(e[i],10));return t}getRecordField(e,t,i,r=0){if(r==="all"){let o=[];for(let d in e.noticeContent.f[t])o.push(this.getRecordSubfields(e.noticeContent.f[t][d],i));return o}try{return this.getRecordSubfields(e.noticeContent.f[t][r],i)}catch{}}getRecordSubfields(e,t){if(typeof t=="string")return e[t];let i={};for(let r in t)i[t[r]]=e[t[r]];return i}formalizeUnimarcLanguage(e){switch(e){case"fre":return"Français";case"eng":return"Anglais";case"ger":return"Allemand";case"spa":return"Espagnol";case"ita":return"Italien";default:return e}}scrollToSavedPosition(){if(sessionStorage.getItem("savedPosition")&&JSON.parse(sessionStorage.getItem("savedPosition"))){let e=JSON.parse(sessionStorage.getItem("savedPosition"));window.scrollTo(parseInt(e.left),parseInt(e.top)),sessionStorage.removeItem("savedPosition")}}async setData(e,t,i){var r=[];switch(i){case"notice":this.recordsLoaded=t,this.recordsLoaded>e.length&&(this.recordsLoaded=0);var o=this.divideRecordArray(e,i),d=await this.getRecordInformations(this.get("sessionId"),o);break;case"bulletin":this.bulletinsLoaded=t,this.recordsLoaded>e.length&&(this.bulletinsLoaded=0);var o=this.divideRecordArray(e,i),d=await this.get("ws").getBulletinExpl(this.get("sessionId"),o);break}return d.forEach(l=>{r.push(l)}),r}divideRecordArray(e,t){let i=[];switch(t){case"bulletin":var r=this.bulletinsLoaded;if(this.recordsToLoad+r>e.length){for(this.bulletinsLoaded;this.bulletinsLoaded!==e.length;this.bulletinsLoaded++)i.push(e[this.bulletinsLoaded]);return i}for(this.bulletinsLoaded;this.bulletinsLoaded<this.recordsToLoad+r;this.bulletinsLoaded++)i.push(e[this.bulletinsLoaded]);break;case"notice":var r=this.recordsLoaded;if(this.recordsToLoad+r>e.length){for(this.recordsLoaded;this.recordsLoaded!==e.length;this.recordsLoaded++)i.push(e[this.recordsLoaded]);return i}for(this.recordsLoaded;this.recordsLoaded<this.recordsToLoad+r;this.recordsLoaded++)i.push(e[this.recordsLoaded]);break}return i}isAvailable(e=[]){var t=null;if(!e.length)return"";if(e.length===1)return e[0].situation;for(let i in e){if(e[i].situation==="Disponible")return e[i].situation;e[i].pret_date_raw.length&&(t?Date.parse(e[i].pret_date_raw)<Date.parse(e[t].pret_date_raw)&&(t=i):t=i)}return t?e[t].situation:e[0].situation}getResaDispo(e){var t=!1;switch(parseInt(this.getConfig().resaDispo)){case 0:e!=="Disponible"&&e.includes("Retour")&&(t=!0);break;case 1:t=!0;break;case 2:e==="Disponible"&&(t=!0);break}return t}getEarliestReturnIndex(e){if(e.length===1)return e[0].i;let t=Math.min(e),i=e.indexOf(t);return i=new Date(i),i.toLocaleDateString()}}export{I as default};
