import{b as Z}from"./chunk-YICBAQ54.js";import{i as P}from"./chunk-2Q4UZQRZ.js";import{Bb as p,Cb as v,Da as K,Db as W,Eb as M,Mb as Y,Nb as J,Ob as Q}from"./chunk-XS4DMB2U.js";import{c as X,d as I}from"./chunk-XA6AU52H.js";import{g as S,o as V}from"./chunk-DAYGRJHR.js";import{s as H}from"./chunk-VYUKN3XQ.js";import{c as n}from"./chunk-AYHVL37M.js";import{b as x,h as G}from"./chunk-KXVCY5JT.js";import{Da as g,Ia as F,K as h,Na as k,P as C,Sa as l,Z as L,a as m,b as u,d as A,ga as d,ia as T,za as c}from"./chunk-XNQ3RS5P.js";var ve=(()=>{let s=class s{static fromCartShippingAddressToAddressRelation(e){try{if(!(e!=null&&e.address))return;if(!s.fromCartAddressToAddressInfo(e.address)){console.warn("Invalid address data");return}return{address:s.fromCartAddressToAddressInfo(e.address),type:v.DELIVERY,isSelected:!0,isKeepBillingDataToggled:!!e.isKeepBillingDataToggled,id:-1,party:s.createShippingParty(e.contactPerson)}}catch(t){console.error("Error converting shipping address:",t);return}}static createShippingParty(e){return{type:W.Person,name:(e==null?void 0:e.name)||"",phone:(e==null?void 0:e.phone)||"",email:(e==null?void 0:e.email)||""}}static fromCartBillingAddressToAddressRelation(e){var r,i,o;if(!e)return;let t={type:v.BILLING,isSelected:!0,id:-1,party:{type:((r=e.party)==null?void 0:r.type)||M.Person,name:((i=e.party)==null?void 0:i.name)||"",uniqueId:((o=e.party)==null?void 0:o.uniqueId)||""}};return e!=null&&e.address&&(t.address=s.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=p.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=p.STRADA):(t.streetName=e.street.name,t.streetType=e.street.type,t.streetId=e.street.streetId),t}static fromCartAddressToAddressInfo(e){var i,o,a,f,D,N,R,w,b,B,U,z,$,q,E,O,j;let t;return e.street&&(t={zipCode:e.street.zipCode||"",type:((o=(i=e.street)==null?void 0:i.streetType)==null?void 0:o.type)||"",selectableType:((f=(a=e.street)==null?void 0:a.streetType)==null?void 0:f.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:((D=e.street)==null?void 0:D.number)||"",building:e.building||"",apartment:e.apartment||"",floor:e.floor||"",addressId:e.id||"",staircase:e.staircase||"",streetType:{selectable:((R=(N=e.street)==null?void 0:N.streetType)==null?void 0:R.selectable)||((b=(w=e.street)==null?void 0:w.streetType)==null?void 0:b.type)||p.STRADA,type:((U=(B=e.street)==null?void 0:B.streetType)==null?void 0:U.type)||p.STRADA,articulate:(($=(z=e.street)==null?void 0:z.streetType)==null?void 0:$.articulate)||((E=(q=e.street)==null?void 0:q.streetType)==null?void 0:E.type)||p.STRADA,shortName:((j=(O=e.street)==null?void 0:O.streetType)==null?void 0:j.shortName)||p.STRADA}}}static toAddressResource(e){var i,o,a;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:((i=t.street)==null?void 0:i.streetId)||"",streetType:this.toStreetTypeOrDefault(t.streetType),name:((o=t.street)==null?void 0:o.name)||t.streetName||"Principala",number:t.streetNo,zipCode:(a=t.street)==null?void 0:a.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"}:m({},e)}static toPersonContactData(e){return{name:e.name,phone:e.phone,email:e.email}}constructor(e,t,r,i,o,a){this.httpClient=e,this.storeSelector=t,this.store=r,this.actions$=i,this.confirmDialogService=o,this.cartApolloClientService=a}getLatestShipping(){return this.httpClient.get(n.getUserAddressesUrl(),{withCredentials:!0}).pipe(C(e=>e.filter(({addressId:t})=>t))).pipe(d(1))}getById(e){return this.httpClient.get("".concat(n.getUserAddressInfo(),"/address/").concat(e))}saveGlobalAddress(e){return this.httpClient.post(n.getAddressInfoUrl(),e,{withCredentials:!0})}saveAddressRelation(r){var i=r,{id:e}=i,t=A(i,["id"]);return e?this.httpClient.put("".concat(n.getUserAddressesUrl(),"/relations/").concat(e),u(m({id:e},t),{isSelected:!0}),{withCredentials:!0}):this.httpClient.post("".concat(n.getUserAddressesUrl(),"/relations"),t,{withCredentials:!0})}forEffectSaveB2cAddress(r){var i=r,{address:e}=i,t=A(i,["address"]);return this.store.select(S).pipe(d(1)).pipe(g(o=>o?this.saveAddressRelation(u(m({},t),{address:s.fromFormAddressToSaveAddress(e),isSelected:!0})).pipe(d(1)):this.saveGlobalAddress(s.fromFormAddressToSaveAddressNotLogged(e)).pipe(d(1)).pipe(C(a=>u(m({},t),{id:-1,address:a})))))}getAddressRelations(e,t){let r=new x;return r=r.set("type",e),t&&(r=r.set("customerNo",t)),this.httpClient.get("".concat(n.getUserAddressesUrl(),"/relations"),{params:r,withCredentials:!0}).pipe(c(1))}deleteAddressRelations(e){return this.httpClient.delete("".concat(n.getUserAddressesUrl(),"/relations/").concat(e),{withCredentials:!0}).pipe(c(1))}patchSelectedAddress(e,t,r){return this.httpClient.put("".concat(n.getUserAddressesUrl(),"/relations/").concat(e),u(m({},t),{address:r}),{withCredentials:!0}).pipe(c(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(F(this.store.select(S))).pipe(g(([t,r])=>this.handleDeleteAddress(t,e,r))).pipe(d(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:K,variables:{request:{cui:e}}})}handleDeleteAddress(e,t,r){return e&&t.id?r?this.deleteAddressRelation(t):h(!0):h(!1)}deleteAddressRelation(e){return this.store.dispatch(Y({addressToDelete:e})),L(this.actions$.pipe(I(J)).pipe(T(!0)),this.actions$.pipe(I(Q)).pipe(T(!1)))}};s.\u0275fac=function(t){return new(t||s)(l(G),l(V),l(H),l(X),l(P),l(Z))},s.\u0275prov=k({token:s,factory:s.\u0275fac,providedIn:"root"});let y=s;return y})();export{ve as a};