import{b as j}from"./chunk-SMNAC7CE.js";import{i as L}from"./chunk-DEYVTPB3.js";import{Wa as a,Xa as T,Y as w,Ya as U,Za as z,fb as q,gb as B,hb as E}from"./chunk-73GUXIT2.js";import{c as O,d as S}from"./chunk-GXS7C5SQ.js";import{g,o as $}from"./chunk-JJTPXY4D.js";import{s as b}from"./chunk-ALDBR463.js";import{c as s}from"./chunk-2G3AB74T.js";import{b as N,h as D}from"./chunk-VWCGOHBE.js";import{Da as v,F as f,Ia as R,K as A,Na as n,U as I,a as l,b as c,ba as p,d as y,da as h,ua as m,ya as C}from"./chunk-V6BPA3D7.js";var ae=(()=>{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:T.DELIVERY,isSelected:!0,shippingAddressSourceSubResource:e.shippingAddressSourceSubResource,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:T.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,d,u){this.httpClient=e,this.storeSelector=t,this.store=r,this.actions$=o,this.confirmDialogService=d,this.cartApolloClientService=u}getLatestShipping(){return this.httpClient.get(s.getUserAddressesUrl(),{withCredentials:!0}).pipe(A(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=y(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=y(o,["address"]);return this.store.select(g).pipe(p(1)).pipe(C(d=>d?this.saveAddressRelation(c(l({},t),{address:i.fromFormAddressToSaveAddress(e),isSelected:!0})).pipe(p(1)):this.saveGlobalAddress(i.fromFormAddressToSaveAddressNotLogged(e)).pipe(p(1)).pipe(A(u=>c(l({},t),{id:-1,address:u})))))}getAddressRelations(e,t){let r=new N;return r=r.set("type",e),t&&(r=r.set("customerNo",t)),this.httpClient.get(`${s.getUserAddressesUrl()}/relations`,{params:r,withCredentials:!0}).pipe(m(1))}deleteAddressRelations(e){return this.httpClient.delete(`${s.getUserAddressesUrl()}/relations/${e}`,{withCredentials:!0}).pipe(m(1))}patchSelectedAddress(e,t,r){return this.httpClient.put(`${s.getUserAddressesUrl()}/relations/${e}`,c(l({},t),{address:r}),{withCredentials:!0}).pipe(m(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(v(this.store.select(g))).pipe(C(([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:w,variables:{request:{cui:e}}})}handleDeleteAddress(e,t,r){return e&&t.id?r?this.deleteAddressRelation(t):f(!0):f(!1)}deleteAddressRelation(e){return this.store.dispatch(q({addressToDelete:e})),I(this.actions$.pipe(S(B)).pipe(h(!0)),this.actions$.pipe(S(E)).pipe(h(!1)))}static{this.\u0275fac=function(t){return new(t||i)(n(D),n($),n(b),n(O),n(L),n(j))}}static{this.\u0275prov=R({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();export{ae as a};