import{b as L}from"./chunk-YS6HBWHP.js";import{i as F}from"./chunk-PE3EBM2W.js";import{Bb as a,Cb as S,Da as B,Db as U,Eb as z,Mb as q,Nb as E,Ob as O}from"./chunk-OD6CMNJH.js";import{c as j,d as v}from"./chunk-O7JFACMN.js";import{g as T,n as $}from"./chunk-O2KDIBGD.js";import{s as w}from"./chunk-QUA65JBC.js";import{c as s}from"./chunk-Z5BNBYBS.js";import{b as R,h as b}from"./chunk-SAGV4YDN.js";import{Ca as g,Ha as D,J as A,Ma as N,O as h,Ra as n,Y as I,a as l,b as c,d as f,fa as p,ha as C,ya as d}from"./chunk-NRAZ4AKM.js";var pe=(()=>{let i=class i{static fromCartShippingAddressToAddressRelation(e){try{if(!e?.address)return;if(!i.fromCartAddressToAddressInfo(e.address)){console.warn("Invalid address data");return}return{address:i.fromCartAddressToAddressInfo(e.address),type:S.DELIVERY,isSelected:!0,isKeepBillingDataToggled:!!e.isKeepBillingDataToggled,id:-1,party:i.createShippingParty(e.contactPerson)}}catch(t){console.error("Error converting shipping address:",t);return}}static createShippingParty(e){return{type:U.Person,name:e?.name||"",phone:e?.phone||"",email:e?.email||""}}static fromCartBillingAddressToAddressRelation(e){if(!e)return;let t={type:S.BILLING,isSelected:!0,id:-1,party:{type:e.party?.type||z.Person,name:e.party?.name||"",uniqueId:e.party?.uniqueId||""}};return e?.address&&(t.address=i.fromCartAddressToAddressInfo(e.address)),t}static fromFormAddressToSaveAddress(e){let t={county:e.county.name,locality:e.locality.uniqueNameOnCounty||e.locality.name,streetNo:e.streetNo,building:e.building,staircase:e.staircase,apartment:e.apartment,zipcode:e.zipCode,createdBy:"eshop"+s.getChannel()};return typeof e.street=="string"?(t.streetName=e.street,t.streetType=a.STRADA):(t.streetName=e.street.name,t.streetType=e.street.type,t.streetId=e.street.streetId),t}static fromFormAddressToSaveAddressNotLogged(e){let t={county:e.county.mnemonic,locality:e.locality.uniqueNameOnCounty||e.locality.name,streetNo:e.streetNo,building:e.building,staircase:e.staircase,apartment:e.apartment,zipcode:e.zipCode,createdBy:"eshop"+s.getChannel()};return typeof e.street=="string"?(t.streetName=e.street,t.streetType=a.STRADA):(t.streetName=e.street.name,t.streetType=e.street.type,t.streetId=e.street.streetId),t}static fromCartAddressToAddressInfo(e){let t;return e.street&&(t={zipCode:e.street.zipCode||"",type:e.street?.streetType?.type||"",selectableType:e.street?.streetType?.selectable||"",name:e.street.name||"",streetId:e.street.id||""}),{zipCode:e.zipCode||"",street:t,locality:{uniqueNameOnCounty:e.locality.uniqueNameOnCounty||"",name:e.locality.name,siruta:e.locality.id,uatSiruta:e.locality.id,type:e.locality.type},county:{mnemonic:e.county.mnemonic||"",name:e.county.name||"",siruta:e.county.id,type:e.county.type},streetNo:e.street?.number||"",building:e.building||"",apartment:e.apartment||"",floor:e.floor||"",addressId:e.id||"",staircase:e.staircase||"",streetType:{selectable:e.street?.streetType?.selectable||e.street?.streetType?.type||a.STRADA,type:e.street?.streetType?.type||a.STRADA,articulate:e.street?.streetType?.articulate||e.street?.streetType?.type||a.STRADA,shortName:e.street?.streetType?.shortName||a.STRADA}}}static toAddressResource(e){let t=e.address,r=e.id;if(!t)throw Error("Address not defined");return{id:t.addressId,onlineAddressId:r,county:{id:t.county.siruta,type:t.county.type,name:t.county.name,mnemonic:t.county.mnemonic},locality:{id:t.locality.siruta,type:t.locality.type,name:t.locality.name,uniqueNameOnCounty:t.locality.uniqueNameOnCounty},street:{id:t.street?.streetId||"",streetType:this.toStreetTypeOrDefault(t.streetType),name:t.street?.name||t.streetName||"Principala",number:t.streetNo,zipCode:t.street?.zipCode},building:t.building,staircase:t.staircase,floor:t.floor,apartment:t.apartment,zipCode:t.zipCode}}static toStreetTypeOrDefault(e){return Object.keys(e).length===0?{selectable:"STRADA",type:"Strad\u0103",articulate:"Strada",shortName:"STR"}:l({},e)}static toPersonContactData(e){return{name:e.name,phone:e.phone,email:e.email}}constructor(e,t,r,o,u,y){this.httpClient=e,this.storeSelector=t,this.store=r,this.actions$=o,this.confirmDialogService=u,this.cartApolloClientService=y}getLatestShipping(){return this.httpClient.get(s.getUserAddressesUrl(),{withCredentials:!0}).pipe(h(e=>e.filter(({addressId:t})=>t))).pipe(p(1))}getById(e){return this.httpClient.get(`${s.getUserAddressInfo()}/address/${e}`)}saveGlobalAddress(e){return this.httpClient.post(s.getAddressInfoUrl(),e,{withCredentials:!0})}saveAddressRelation(r){var o=r,{id:e}=o,t=f(o,["id"]);return e?this.httpClient.put(`${s.getUserAddressesUrl()}/relations/${e}`,c(l({id:e},t),{isSelected:!0}),{withCredentials:!0}):this.httpClient.post(`${s.getUserAddressesUrl()}/relations`,t,{withCredentials:!0})}forEffectSaveB2cAddress(r){var o=r,{address:e}=o,t=f(o,["address"]);return this.store.select(T).pipe(p(1)).pipe(g(u=>u?this.saveAddressRelation(c(l({},t),{address:i.fromFormAddressToSaveAddress(e),isSelected:!0})).pipe(p(1)):this.saveGlobalAddress(i.fromFormAddressToSaveAddressNotLogged(e)).pipe(p(1)).pipe(h(y=>c(l({},t),{id:-1,address:y})))))}getAddressRelations(e,t){let r=new R;return r=r.set("type",e),t&&(r=r.set("customerNo",t)),this.httpClient.get(`${s.getUserAddressesUrl()}/relations`,{params:r,withCredentials:!0}).pipe(d(1))}deleteAddressRelations(e){return this.httpClient.delete(`${s.getUserAddressesUrl()}/relations/${e}`,{withCredentials:!0}).pipe(d(1))}patchSelectedAddress(e,t,r){return this.httpClient.put(`${s.getUserAddressesUrl()}/relations/${e}`,c(l({},t),{address:r}),{withCredentials:!0}).pipe(d(1))}deleteAddressWithConfirmation(e){return this.confirmDialogService.confirm({title:"Eliminare adres\u0103",paragraphs:["E\u0219ti sigur c\u0103 vrei s\u0103 \u0219tergi adresa?"],btnCancelText:"Renun\u021B\u0103",btnOkText:"Da"}).pipe(D(this.store.select(T))).pipe(g(([t,r])=>this.handleDeleteAddress(t,e,r))).pipe(p(1))}cancelAddressWithConfirmation(){return this.confirmDialogService.confirm({title:"Anulare completare adres\u0103",paragraphs:["E\u0219ti sigur c\u0103 vrei s\u0103 anulezi completarea adresei?"],btnCancelText:"Renun\u021B\u0103",btnOkText:"Da"})}getBillingAddressByCui(e){return this.cartApolloClientService.query({query:B,variables:{request:{cui:e}}})}handleDeleteAddress(e,t,r){return e&&t.id?r?this.deleteAddressRelation(t):A(!0):A(!1)}deleteAddressRelation(e){return this.store.dispatch(q({addressToDelete:e})),I(this.actions$.pipe(v(E)).pipe(C(!0)),this.actions$.pipe(v(O)).pipe(C(!1)))}};i.\u0275fac=function(t){return new(t||i)(n(b),n($),n(w),n(j),n(F),n(L))},i.\u0275prov=N({token:i,factory:i.\u0275fac,providedIn:"root"});let m=i;return m})();export{pe as a};