import{P as r}from"./BCLrUOBx.js";const d={data(){return{fetchingAddressData:!1}},methods:{async addressAction(){var s,a;if(this.addressData.email&&this.addressData.city&&this.addressData.phone&&this.addressData.name&&this.addressData.zip&&this.addressData.country&&this.addressData.address_1){this.submittingAddressData=!0;const t=await this.postRequest({api:"userAddressAction",params:{...this.addressData,user_token:await this.getUserToken()}});(t==null?void 0:t.status)===200?(this.hasAddressErrors=!1,this.updateAddress(t==null?void 0:t.data),this.setToastMessage(t.message)):(t==null?void 0:t.status)===201?this.setToastError((a=(s=t.data)==null?void 0:s.form)==null?void 0:a.join(", ")):this.hasError(t),this.submittingAddressData=!1}else this.hasAddressErrors=!0},async deleting(s){var a,t;if(confirm(this.$t("cartProductTile.deleteAlert"))){this.ajaxDeleting=s.id;const e=await this.deleteRequest({api:"userAddressDelete",params:`/${s.id}?${r({user_token:await this.getUserToken()})}`});(e==null?void 0:e.status)===200?(this.setToastMessage(e.message),await this.fetchingData()):this.setToastError((t=(a=e==null?void 0:e.data)==null?void 0:a.form)==null?void 0:t.join(", ")),this.ajaxDeleting=0}},formatAddress(s){let a=[];if(a.push(s.address_1),s.address_2&&a.push(s.address_2),a.push(s.city+"-"+s.zip),this.countryList[s.country]){const e=this.countryList[s.country];e.states[s.state]&&a.push(e.states[s.state].name),a.push(e.name)}return a.filter(function(e){return e!=null}).join(", ")},async fetchingData(){this.fetchingAddressData=!0,setTimeout(async()=>{this.settingRouteParam();const s=await this.getRequest({api:"userAddressAll",params:`?${r({time_zone:this.timeZone,order_by:this.orderBy,type:this.orderByType,page:this.page,user_token:await this.getUserToken(),q:this.search})}`});(s==null?void 0:s.status)!==200?this.hasError(s):this.setAllAddress(s==null?void 0:s.data),this.fetchingAddressData=!1},100)}}};export{d as a};
