import k from"./CWalxxGV.js";import y from"./Bvs3L9q-.js";import _ from"./YMgwR3Gi.js";import{u as P}from"./Bxmfm8sn.js";import{v as S}from"./7BSVXI-E.js";import{K as E,i as w,j as a,w as g,k as o,l as h,v as F,t as n,m as i,C as f,D as C,A as b,E as v,P as T,a as D,b as R,u as $,s as q}from"./BCLrUOBx.js";import{u as U}from"./BXig4bti.js";const B={setup(){const e=D(),{getUserToken:t}=e,d=R(),{setToastMessage:m,setToastError:s,getRequest:l,postRequest:c}=d,p=U(),{cancellationFind:u}=p,r=$(),{langCode:M}=q(r);return{getUserToken:t,cancellationFind:u,setToastMessage:m,getRequest:l,setToastError:s,langCode:M,postRequest:c}},name:"OrderCancelPopup",data(){return{title:"",cancellationMessage:"",submitting:!1,hasFormError:!1,fetchingCancelledData:!1}},props:{orderId:{type:Number,required:!0}},components:{AjaxButton:y,PopOver:_,Spinner:k},mixins:[P,S],methods:{serializing(e){this.title=e.title,this.cancellationMessage=e.message},async submitForm(){var e;if(this.title&&this.cancellationMessage){this.submitting=!0;const t=await this.postRequest({api:"cancelOrder",params:{user_token:await this.getUserToken(),order_id:this.orderId,message:this.cancellationMessage,title:this.title},lang:this.langCode});this.submitting=!1,(t==null?void 0:t.status)===200?(this.$emit("success"),this.setToastMessage(t.message)):(t==null?void 0:t.status)===204?this.setToastError(t.message):this.setToastError((e=t.data)==null?void 0:e.form.join(", "))}else this.hasFormError=!0}},async mounted(){this.fetchingCancelledData=!0;const e=await this.getRequest({api:"cancellationFind",params:`/${this.orderId}?${T({id:this.orderId,user_token:await this.getUserToken()})}`,lang:this.langCode});(e==null?void 0:e.status)===200&&this.serializing(e.data),this.fetchingCancelledData=!1}},O={key:0,class:"mn-h-200x flex"},V={key:1},j=["placeholder"],x={key:0,class:"error"},I={key:0,class:"error"},N={class:"flex j-end gap-10"};function z(e,t,d,m,s,l){const c=k,p=y,u=_;return a(),w(u,{title:e.$t("orderCancelPopup.cancelOrder"),onClose:t[3]||(t[3]=r=>e.$emit("close")),"elem-id":"cancel-order-pop-over",layer:!0,class:"cancel-popup"},{content:g(()=>[s.fetchingCancelledData?(a(),i("div",O,[h(c,{radius:70})])):(a(),i("div",V,[o("div",{class:f(["input-wrap",{invalid:!s.title&&s.hasFormError}])},[o("label",null,n(e.$t("orderCancelPopup.title")),1),C(o("input",{type:"text","onUpdate:modelValue":t[0]||(t[0]=r=>s.title=r),placeholder:e.$t("contact.your",{type:e.$t("orderCancelPopup.titleSmall")})},null,8,j),[[v,s.title]]),!s.title&&s.hasFormError?(a(),i("span",x,n(e.$t("addressPopup.isRequired",{type:e.$t("orderCancelPopup.title")})),1)):b("",!0)],2),o("div",{class:f(["input-wrap mb-0",{invalid:!s.cancellationMessage&&s.hasFormError}])},[o("label",null,n(e.$t("addressPopup.message")),1),C(o("textarea",{"onUpdate:modelValue":t[1]||(t[1]=r=>s.cancellationMessage=r)},null,512),[[v,s.cancellationMessage]]),!s.cancellationMessage&&s.hasFormError?(a(),i("span",I,n(e.$t("addressPopup.isRequired",{type:e.$t("addressPopup.message")})),1)):b("",!0)],2)]))]),"pop-footer":g(()=>[o("div",N,[o("button",{"aria-label":"close",class:"outline-btn plr-30 plr-sm-15",onClick:t[2]||(t[2]=F(r=>e.$emit("close"),["prevent"]))},n(e.$t("addressPopup.cancel")),1),h(p,{class:"primary-btn plr-30 plr-sm-15",type:"button","fetching-data":s.submitting,"loading-text":e.$t("checkoutRight.submitting"),text:e.$t("orderCancelPopup.SendMessage"),disabled:s.fetchingCancelledData,onClicked:l.submitForm},null,8,["fetching-data","loading-text","text","disabled","onClicked"])])]),_:1},8,["title"])}const W=E(B,[["render",z]]);export{W as default};
