import{a as W,b as Z,e as X}from"./chunk-TRGMQ6EL.js";import{a as ie,c as se}from"./chunk-TOEJH65F.js";import{b as w}from"./chunk-ROVQNOEI.js";import{e as ee,o as te,q as re}from"./chunk-525REWT5.js";import{b as Y}from"./chunk-7RLAFGY6.js";import{$ as M,A as E,Ba as D,M as m,O as I,P,T as U,Yb as f,Z as p,Zb as g,Zd as B,_ as L,aa as s,ac as V,bc as F,bd as x,ce as Q,de as j,f as ve,fe as z,he as v,j as O,ld as $,md as _,mg as Se,n as d,na as K,ne as G,o as R,og as J,p as a,qe as u,r as b,re as l,s as h,se as T,ve as q,we as N}from"./chunk-33PV2Q5J.js";var oe=(()=>{class i{constructor(e,t,r,o){this.httpClient=e,this.addressConverter=t,this.endpoints=r,this.urlHelper=o,this.countryStateRequests=new Map}getMyAddresses(e,t={page:"0",size:se}){return h(()=>{let r=new f().set("Content-Type","application/json"),o=Object.assign({},t);return this.httpClient.get(this.urlHelper.apiUrl(this.endpoints.commerce.customer.address+"/"+e+"/"),{headers:r,params:o})})}updateAddress(e){return h(()=>{let t=new f().set("Content-Type","application/json");return this.httpClient.put(this.urlHelper.apiUrl(this.endpoints.commerce.customer.address),e,{headers:t})})}getMyDefaultAddress(e){return h(()=>{let t=new f().set("Content-Type","application/json"),r=`${this.endpoints.commerce.customer.address}/${e}/default`;return this.httpClient.get(this.urlHelper.apiUrl(r),{headers:t})}).pipe(a(t=>this.addressConverter.convertToAddressModel(t)),E(t=>(console.log(t),d(new te))))}updateOrCreate(e){return h(()=>{let t=new f().set("Content-Type","application/json"),r=`${this.endpoints.commerce.customer.address}/${e.addressType}`;return this.httpClient.put(this.urlHelper.apiUrl(r),e,{headers:t})})}delete(e){return h(()=>{let t=new f().set("Content-Type","application/json"),r=`${this.endpoints.commerce.customer.address}/${e.addressType}/${e.addressId}`;return this.httpClient.delete(this.urlHelper.apiUrl(r),{headers:t}).pipe(a(()=>null))})}getPickup(){let e=new f().set("Content-Type","application/json"),t=this.endpoints.commerce.customer.pickup;return this.httpClient.get(this.urlHelper.apiUrl(t),{headers:e})}getStatesByCountryCode(e){let t=this.countryStateRequests.get(e);return t||(t=this.getCountryStates(e).pipe(I()),this.countryStateRequests.set(e,t),t)}getCountryStates(e){let t=new f().set("Content-Type","application/json"),r=`${this.endpoints.commerce.customer.address}/options/country/${e}`;return this.httpClient.get(this.urlHelper.apiUrl(r),{headers:t})}static{this.\u0275fac=function(t){return new(t||i)(s(T),s(re),s(l),s(u))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var y=class{constructor(){this.customerType="B2C"}};var H=class{constructor(){this.custom=new y}};var ne=new M("AuthStorageService"),Fe="access_token",xe="refresh_token",$e="user_email";var ae={"api-version":"V2"},ce=(()=>{class i{constructor(e,t,r,o,c,n,C,A,Te,Ee,ge){this.http=e,this.httpClient=t,this.jwtHelper=r,this.environment=o,this.endpoints=c,this.platformId=n,this.urlHelper=C,this.language=A,this.authStorageService=Te,this.langService=Ee,this.origin=ge,this.serviceBaseUrl=this.environment.auth.apiUrl,this.oauthTokenUrl=this.endpoints.auth.oauthToken,this.changePasswordUrl=this.endpoints.auth.changePassword,this.resetPasswordUrl=this.endpoints.auth.resetPassword,this.reauthorizingErrorSubject=new O,this.refreshToken$=this.refreshTokenObservable().pipe(I())}getAccessToken(){return h(()=>{let e=this.authStorageService.getAccessToken();return d(e)})}getRefreshToken(){return h(()=>{let e=this.authStorageService.getRefreshToken();return d(e)})}isLoggedIn(){return this.getRefreshToken().pipe(a(e=>!!e))}login(e,t){return this.getTokenByCredentials(e,t).pipe(m(r=>this.saveToken(r)),a(r=>r!==null))}refreshToken(){return this.refreshToken$}refreshTokenObservable(){return this.getRefreshToken().pipe(m(e=>e?this.getTokenByRefreshToken(e):R(new z("Refresh token hasn't been stored"))),m(e=>this.saveToken(e)),a(e=>e.access_token))}logout(){return this.authStorageService.clear().pipe(a(()=>!0))}register(e,t){let r=new H;return r.email=e,r.password=t,r.returnUrl=this.origin,r.language=this.langService.getCurrentLang(),this.http.post(this.urlHelper.authUrl(this.endpoints.auth.register),r)}observeLoginDataChanges(){return this.authStorageService.observeLoginDataChanges()}getLoginData(){return this.authStorageService.getLoginData()}getTokenByCredentials(e,t){let r=new g().set("grant_type","password").set("username",e).set("password",t).set("client_id",this.environment.auth.clientId);return this.http.post(this.serviceBaseUrl+this.oauthTokenUrl,r,{headers:ae})}getTokenByRefreshToken(e){let t=new g().set("grant_type","refresh_token").set("refresh_token",e).set("client_id",this.environment.auth.clientId);return this.http.post(this.serviceBaseUrl+this.oauthTokenUrl,t,{headers:ae}).pipe(m(r=>this.saveToken(r)),E(r=>(this.reauthorizingErrorSubject.next(new Q(r)),R(r))))}changePassword(e,t){let r={oldPassword:e,password:t};return this.httpClient.put(this.serviceBaseUrl+this.changePasswordUrl,r)}observeReauthorizeErrors(){return this.reauthorizingErrorSubject.asObservable()}saveToken(e){return this.authStorageService.save(e).pipe(a(()=>e))}resetPassword(e){let t={email:e,returnUrl:this.origin};return this.httpClient.post(this.serviceBaseUrl+this.resetPasswordUrl,t)}checkPermission(e){return this.getAccessToken().pipe(a(t=>t?this.jwtHelper.decodeToken(t||""):d(!0)),a(t=>t.tenancies_authorities?t.tenancies_authorities.hasOwnProperty(e):!1))}static{this.\u0275fac=function(t){return new(t||i)(s(V),s(T),s(v),s($),s(l),s(K),s(u),s(B),s(ne),s(_),s("ORIGIN_URL"))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var pe=ve(Se());var he=(()=>{class i{constructor(e,t,r){this.authService=e,this.jwtHelper=t,this.endpoints=r}intercept(e,t){return e.url.includes(this.endpoints.auth.oauthToken)?t.handle(e):this.authService.isLoggedIn().pipe(b(r=>r?this.authService.getAccessToken().pipe(m(o=>this.refreshTokenIfExpired(e,o)),m(o=>this.attachTokenAndSend(e,t,o)),E(o=>this.catchErrors(e,t,o))):t.handle(e)))}refreshTokenIfExpired(e,t){return!this.isRefreshRequest(e)&&t!=null&&this.jwtHelper.isTokenExpired(t)?this.authService.refreshToken():d(t)}attachTokenAndSend(e,t,r){return h(()=>{let o=e.clone({setHeaders:{Authorization:`Bearer ${r}`}});return t.handle(o)})}catchErrors(e,t,r){return r.status===pe.UNAUTHORIZED?this.authService.refreshToken().pipe(U(o=>this.attachTokenAndSend(e,t,o)),E(o=>this.authService.logout().pipe(m(()=>R(o))))):R(r)}isRefreshRequest(e){return e.body instanceof g?e.body.has("refresh_token"):!1}static{this.\u0275fac=function(t){return new(t||i)(s(j),s(v),s(l))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac})}}return i})();var ue=(()=>{class i{constructor(){}productSearchResponseToProductResponseModel(e){let t=[];return e.forEach(r=>{let o=Object.assign({},r),c=[];r.attributes.forEach(n=>{let A={attribute:{attributeId:0,code:n.attribute.code,mandatory:!1,search:n.attribute.search,navigation:n.attribute.navigation,val:null,name:n.attribute.name,description:"",etypeId:0,etypeName:"",attributegroupId:0,allowduplicate:!1,allowfailover:!1,regexp:null,validationFailedMessage:"",rank:0,choiceData:"",displayNames:n.attribute.displayNames},attributeCode:n.code,val:n.value,attributeName:n.attribute.name,displayVals:n.displayValue,galleryImages:[]};c.push(A)}),o.attributes=c,t.push(o)}),t}responseToProductSearchResponseModel(e){return{search:e.search,totalResults:e.totalResults,productImageWidth:e.productImageWidth,productImageHeight:e.productImageHeight,pageAvailableSort:e.pageAvailableSort,pageAvailableSize:e.pageAvailableSize,products:this.productSearchResponseToProductResponseModel(e.products),filteredNavigation:e.filteredNavigation}}static{this.\u0275fac=function(t){return new(t||i)}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var le=(()=>{class i{constructor(e,t,r,o){this.httpClient=e,this.urlHelper=t,this.endpoints=r,this.searchResponseConverter=o}search(e){return this.httpClient.put(this.urlHelper.apiUrl(this.endpoints.commerce.search),e).pipe(a(t=>this.searchResponseConverter.responseToProductSearchResponseModel(t)))}static{this.\u0275fac=function(t){return new(t||i)(s(T),s(u),s(l),s(ue))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var me=(()=>{class i{constructor(e){this.currency=e}static{this.filter="price"}convert(e){let t=e;return{price:[`${this.currency}-_-${t.from}-_-${t.to}`]}}}return i})(),de=(()=>{class i{prepareConverters(e){let t=new Map;return t.set(me.filter,new me(e)),t}constructor(e){this.cartManagementService=e,this.cartCurrencySubscription=this.cartManagementService.observeCart().pipe(a(t=>t?t.currencyCode:q)).subscribe(t=>{this.productFilterToQueryConverters=this.prepareConverters(t)},console.log)}convertToQuery(e,t){let r={};e.forEach(c=>{if(c instanceof W){let n=this.productFilterToQueryConverters.get(c.searchQueryParam);n?r=Object.assign(r,n.convert(c)):r[c.searchQueryParam]=[`${c.from}-_-${c.to}`]}else if(c instanceof Z){let n=c.filterValues.filter(C=>C.checked);n.length>0&&(r[c.searchQueryParam]=n.map(C=>C.defaultValue))}});let o={parameters:r};return t!=null&&(o.category=t),o}ngOnDestroy(){this.cartCurrencySubscription&&this.cartCurrencySubscription.unsubscribe()}static{this.\u0275fac=function(t){return new(t||i)(s(G))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac})}}return i})();var fe=(()=>{class i{constructor(e,t,r,o){this.httpClient=e,this.urlHelper=t,this.endpoints=r,this.translatesService=o,this.contentRequests=new Map}getContent(e){let t=new g().set("locale",this.translatesService.getCurrentLang()),r=this.contentRequests.get(e);return r||(r=this.httpClient.get(this.urlHelper.apiUrl(this.endpoints.commerce.content.view+"/"+e),{params:t}).pipe(P(1)),this.contentRequests.set(e,r)),r}static{this.\u0275fac=function(t){return new(t||i)(s(T),s(u),s(l),s(_))}}static{this.\u0275prov=p({token:i,factory:i.\u0275fac})}}return i})();var nr=(()=>{class i{static{this.\u0275fac=function(t){return new(t||i)}}static{this.\u0275mod=D({type:i})}static{this.\u0275inj=L({providers:[u,{provide:w,useClass:N},{provide:N,useExisting:w},{provide:F,useClass:he,multi:!0},{provide:ie,useClass:oe,multi:!1},{provide:Y,useClass:ee},{provide:j,useClass:ce},{provide:v,useValue:new v},{provide:x,useClass:le},{provide:X,useClass:de},{provide:J,useClass:fe}]})}}return i})();export{ne as a,Fe as b,xe as c,$e as d,ue as e,nr as f};