import{a as x}from"./chunk-CV4K56GJ.js";import{h as F}from"./chunk-U7B53EQX.js";import{Ab as z,Ca as U,Ib as L,Jb as E,Kb as O,xb as d,yb as R,zb as q}from"./chunk-U45OJP77.js";import{c as P,d as N}from"./chunk-VN6PXZL4.js";import{A as k}from"./chunk-HMS3LRP2.js";import{f as B}from"./chunk-PQ4LRPD5.js";import{g as v,l as j,n as A}from"./chunk-MGYJOL7Z.js";import{s as h}from"./chunk-QYQ7WNYU.js";import{b as n}from"./chunk-W73LR43Y.js";import{b as w,h as $}from"./chunk-6MZAHXNO.js";import{Ba as m,Ga as b,J as c,La as y,O as T,Qa as o,Y as D,a as s,b as f,d as S,fa as p,ha as I,xa as u}from"./chunk-HC2G7LSI.js";var H="cart",G=a=>a?{context:{headers:{"X-Profile-Id":`${a}`}}}:{},W=(()=>{let i=class i{constructor(e,t,r,l){this.httpLink=e,this.store=t,this.apollo=r,this.storeSelector=l,this.profileId$=this.getProfileId()}query(e,{profileId:t}={}){return(t?c(t):this.profileId$).pipe(p(1)).pipe(m(r=>this.apollo.use(H).query(s(s({},e),G(r)))))}mutate(e,{profileId:t}={}){return(t?c(t):this.profileId$).pipe(p(1)).pipe(m(r=>this.apollo.use(H).mutate(s(s({},e),G(r)))))}getProfileId(){return this.storeSelector.getWithSelector(j).pipe(m(e=>e?this.storeSelector.getWithSelector(k):c(void 0))).pipe(u(1))}};i.\u0275fac=function(t){return new(t||i)(o(x),o(h),o(B),o(A))},i.\u0275prov=y({token:i,factory:i.\u0275fac,providedIn:"root"});let a=i;return a})();var Ie=(()=>{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:R.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:q.Person,name:e?.name||"",phone:e?.phone||"",email:e?.email||""}}static fromCartBillingAddressToAddressRelation(e){if(!e)return;let t={type:R.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"+n.getChannel()};return typeof e.street=="string"?(t.streetName=e.street,t.streetType=d.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"+n.getChannel()};return typeof e.street=="string"?(t.streetName=e.street,t.streetType=d.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||d.STRADA,type:e.street?.streetType?.type||d.STRADA,articulate:e.street?.streetType?.articulate||e.street?.streetType?.type||d.STRADA,shortName:e.street?.streetType?.shortName||d.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"}:s({},e)}static toPersonContactData(e){return{name:e.name,phone:e.phone,email:e.email}}constructor(e,t,r,l,g,C){this.httpClient=e,this.storeSelector=t,this.store=r,this.actions$=l,this.confirmDialogService=g,this.cartApolloClientService=C}getLatestShipping(){return this.httpClient.get(n.getUserAddressesUrl(),{withCredentials:!0}).pipe(T(e=>e.filter(({addressId:t})=>t))).pipe(p(1))}getById(e){return this.httpClient.get(`${n.getUserAddressInfo()}/address/${e}`)}saveGlobalAddress(e){return this.httpClient.post(n.getAddressInfoUrl(),e,{withCredentials:!0})}saveAddressRelation(r){var l=r,{id:e}=l,t=S(l,["id"]);return e?this.httpClient.put(`${n.getUserAddressesUrl()}/relations/${e}`,f(s({id:e},t),{isSelected:!0}),{withCredentials:!0}):this.httpClient.post(`${n.getUserAddressesUrl()}/relations`,t,{withCredentials:!0})}forEffectSaveB2cAddress(r){var l=r,{address:e}=l,t=S(l,["address"]);return this.store.select(v).pipe(p(1)).pipe(m(g=>g?this.saveAddressRelation(f(s({},t),{address:i.fromFormAddressToSaveAddress(e),isSelected:!0})).pipe(p(1)):this.saveGlobalAddress(i.fromFormAddressToSaveAddressNotLogged(e)).pipe(p(1)).pipe(T(C=>f(s({},t),{id:-1,address:C})))))}getAddressRelations(e,t){let r=new w;return r=r.set("type",e),t&&(r=r.set("customerNo",t)),this.httpClient.get(`${n.getUserAddressesUrl()}/relations`,{params:r,withCredentials:!0}).pipe(u(1))}deleteAddressRelations(e){return this.httpClient.delete(`${n.getUserAddressesUrl()}/relations/${e}`,{withCredentials:!0}).pipe(u(1))}patchSelectedAddress(e,t,r){return this.httpClient.put(`${n.getUserAddressesUrl()}/relations/${e}`,f(s({},t),{address:r}),{withCredentials:!0}).pipe(u(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(b(this.store.select(v))).pipe(m(([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:U,variables:{request:{cui:e}}})}handleDeleteAddress(e,t,r){return e&&t.id?r?this.deleteAddressRelation(t):c(!0):c(!1)}deleteAddressRelation(e){return this.store.dispatch(L({addressToDelete:e})),D(this.actions$.pipe(N(E)).pipe(I(!0)),this.actions$.pipe(N(O)).pipe(I(!1)))}};i.\u0275fac=function(t){return new(t||i)(o($),o(A),o(h),o(P),o(F),o(W))},i.\u0275prov=y({token:i,factory:i.\u0275fac,providedIn:"root"});let a=i;return a})();export{H as a,W as b,Ie as c};