import{Fa as j,f as P}from"./chunk-RTOZFW5D.js";import{a as L}from"./chunk-BJ2UHOXD.js";import{e as v}from"./chunk-E56JCP42.js";import{C as u,E as f,H as c,I as T}from"./chunk-3T7NQNCJ.js";import{D as m,l as p,s as o}from"./chunk-SBF3UK4I.js";import{a as g}from"./chunk-K7QH4WSQ.js";import{Qa as l}from"./chunk-SGK554CS.js";import{e as y,j as n}from"./chunk-YR2ZOLW3.js";import{q as S,x as d}from"./chunk-VI2VOVRS.js";var H=`${l.v1_0}/catalog/orders`,N=(()=>{class a{constructor(e,t,i,s,h,r){this.configService=e,this.headersFactory=t,this.shopApiService=i,this.userService=s,this.authenticationService=h,this.storageService=r,this.sortTypes=[],this.storageKey="selectedSortType",this.orderPriority=this.configService.getCatalogOrderPriority()}clean(){this.storageService.remove(this.storageKey)}cleanStorageTypes(){this.sortTypes=[]}getById(e,t){let i=o(t,s=>s.id===e);return i||this.sortTypes[0]}getDefaultSortType(e,t){let i,s=this.userService.getCustomRecomendations(),h=this.authenticationService.isLogged();return e&&Object.keys(e).length!==0?i=o(t,r=>r.id===e.id):h?s?i=o(this.sortTypes,r=>r.id===this.orderPriority.isLogged_isRGPD):i=o(t,r=>r.id===this.orderPriority.isLogged_isNotRGPD):this.isEmptySelectedSortType()?i=o(t,r=>r.id===this.orderPriority.isNotLogged):i=o(t,r=>r.id===this.getSortTypeSelected().id),i||t[0]}getOrganicSearchSortType(e,t,i){let s=o(t,h=>h.id===i);return s||e||this.sortTypes[0]}getSortList(){if(g.emptyArray(this.sortTypes)){let e=this.getHeaders(),t=L.createHttpParams({isLogged:this.authenticationService.isLogged(),hasRecommendations:this.userService.getCustomRecomendations()});return this.shopApiService.get(H,{headers:e,params:t}).pipe(d(i=>(this.sortTypes=p(i),this.sortTypes)))}else return S(this.sortTypes)}getSortRecommendationId(){let e=this.userService.getCustomRecomendations(),t=this.authenticationService.isLogged();if(e&&t)return this.sortTypes.find(i=>i.id===this.orderPriority.isLogged_isRGPD)?.id}getSortTypeSelected(){return this.storageService.get(this.storageKey)}getSortTypeSelectedId(){let e=this.storageService.get(this.storageKey),t=this.getDefaultSortType(null,this.sortTypes);return e||t?e?e.id:t.id:null}isEmptySelectedSortType(){return m(this.getSortTypeSelected())||Object.keys(this.getSortTypeSelected()).length===0}setSortTypeSelected(e){this.storageService.set(this.storageKey,e)}updateSortList(){let e=null;return this.authenticationService.isLogged()&&g.emptyArray(this.sortTypes)&&this.getSortTypeSelected()&&(e=this.getSortTypeSelected()),this.sortTypes=[],this.getSortList().pipe(d(t=>(this.sortTypes=p(t),this.getDefaultSortType(e||null,t))))}getHeaders(){return this.headersFactory.createHttpHeader([c.locale,c.zone,c.channel,c.userid,c.token,c.ShippingZone])}static{this.\u0275fac=function(t){return new(t||a)(n(u),n(T),n(f),n(P),n(j),n(v))}}static{this.\u0275prov=y({token:a,factory:a.\u0275fac,providedIn:"root"})}}return a})();export{N as a};