import{_ as y}from"./CNIrc0EA.js";import{_ as B,a as _,h as u,$ as f,A as k,s as E,c as o,b as c,t as x,f as l,e as d,d as p,D as F,E as U,W as j,o as r}from"./Bgmy51Qv.js";import{_ as b}from"./DZl4_Bww.js";import{F as S}from"./DuSynPle.js";import{A as v}from"./AmaTRG5a.js";import{u as D}from"./BHvLfWtM.js";import{_ as N}from"./D_7E8SMU.js";import{u as C}from"./7pZkuj9N.js";const K={setup(){const t=C(),{getById:s,setById:e,setImageById:n,emptyAllList:i}=t,a=k(),{mediaStorage:m}=E(a);return{getById:s,setById:e,setImageById:n,emptyAllList:i,mediaStorage:m}},name:"DataPage",data(){return{loading:!1,redirect:!1,formSubmitting:!1,fileUploading:!1,hasError:!1}},props:{result:{type:Object,default(){return null}},emitBeforeSubmit:{type:Boolean,default:!1},name:{type:String,default:""},gate:{type:String,default:null},hash:{type:String,default:""},setApi:{type:String,default:""},setImageApi:{type:String,default:""},getApi:{type:String,default:""},emptyStoreVariable:{type:String,default:null},routeName:{type:String,default:""},validationKeys:{type:Array,default:[]},fileKeys:{type:Array,default(){return[]}}},mixins:[D],components:{ImageInput:b,Spinner:_,AjaxButton:v,ErrorFormatter:y,FileUpload:S,Dropdown:N},computed:{id(){var t,s;return this.isAdding?"":(s=(t=this._.provides[f]||this.$route)==null?void 0:t.params)==null?void 0:s.id},isAdding(){var t,s;return isNaN((s=(t=this._.provides[f]||this.$route)==null?void 0:t.params)==null?void 0:s.id)}},methods:{async uploadFile(t,s=null){try{let e={};if(t){const i=new FormData;this.fileKeys.forEach(a=>{i.append(a,this.result[a])}),i.append("photo",t),e=i}else this.fileKeys.forEach(i=>{e[i]=this.result[i]}),e.photo=s;this.fileUploading=!0;const n=await this.setImageById({id:this.id,params:e,api:this.setImageApi});n&&(!this.gate||this.$can(this.gate,"view"))&&(await this.$emit("result",Object.assign({},n)),await this.$router.push({path:`/${this.routeName}/${this.result.id}`})),this.fileUploading=!1}catch(e){u({statusCode:400,message:e.message})}},redirectingEnable(t){this.redirect=t==="save"},formSubmit(){this.emitBeforeSubmit?this.$emit("before-submit"):this.checkForm()},async checkForm(){var t,s;if(this.validationKeys.findIndex(e=>!this.result[e])>-1)return this.hasError=!0,!1;this.redirectingEnable(event.submitter.name),this.formSubmitting=!0;try{delete this.result.created_at,delete this.result.updated_at;const e=await this.setById({id:this.id,params:this.result,api:this.setApi});e?(this.emptyAllList(this.emptyStoreVariable),await this.$emit("result",Object.assign({},e)),(!this.gate||this.$can(this.gate,"view")&&((t=this.result)!=null&&t.id))&&await this.$router.push({path:`/${this.routeName}${this.redirect?"":"/"+((s=this.result)==null?void 0:s.id)}`,hash:`#${this.hash}`}),await this.$emit("on-success",Object.assign({},e))):this.$refs.formWrapper.scrollIntoView({behavior:"smooth"})}catch(e){u({statusCode:400,message:e.message})}this.formSubmitting=!1},async fetchingData(){try{this.loading=!0,this.$emit("result",Object.assign({},await this.getById({id:this.id,params:{time_zone:this.timeZone},api:this.getApi}))),this.loading=!1}catch(t){u({statusCode:400,message:t.message})}}},async mounted(){this.isAdding||this.$nextTick(()=>{(!this.gate||this.$can(this.gate,"view"))&&this.fetchingData()})}},$={ref:"formWrapper",class:"tab-sidebar"},V={class:"title"},O={class:"form-wrapper"},L={key:0,class:"spinner-wrapper"},R={key:1},W={key:0},z=["src"],P={key:0,class:"dply-felx j-right single-btn"};function T(t,s,e,n,i,a){const m=y,w=_,I=b,A=S,g=v;return r(),o("div",$,[c("h4",V,x(t.$t("profile.form",{name:e.name})),1),c("div",O,[l(m),l(m,{type:"image"}),i.loading?(r(),o("div",L,[l(w,{radius:60,color:"primary",class:"mr-15"})])):d("",!0),i.loading?d("",!0):(r(),o("div",R,[e.fileKeys.length&&(!e.gate||t.$can(e.gate,"edit")||t.$can(e.gate,"create"))?(r(),o("div",W,[t.mediaStorageData.URL===n.mediaStorage?(r(),p(I,{key:0,class:"mb-20 mb-sm-15",saving:i.fileUploading,image:e.result.image,onImageChange:s[0]||(s[0]=h=>a.uploadFile(null,h))},null,8,["saving","image"])):(r(),p(A,{key:1,image:e.result.image,"file-uploading":i.fileUploading,"only-icon":"upload-icon",class:"mb-20 mb-sm-15",onFileUpload:a.uploadFile},null,8,["image","file-uploading","onFileUpload"]))])):e.fileKeys.length&&t.$can(e.gate,"view")?(r(),o("img",{key:1,class:"mx-w-300x",src:t.getImageURL(e.result.image)},null,8,z)):d("",!0)])),c("form",{onSubmit:s[1]||(s[1]=U((...h)=>a.formSubmit&&a.formSubmit(...h),["prevent"])),class:F({"has-error":i.hasError})},[j(t.$slots,"form",{hasError:i.hasError}),!e.gate||t.$can(e.gate,"edit")||t.$can(e.gate,"create")?(r(),o("div",P,[l(g,{name:"save-edit",class:"primary-btn",text:t.$t("list.svn"),"fetching-data":i.formSubmitting&&!i.redirect},null,8,["text","fetching-data"]),l(g,{name:"save",class:"primary-btn",text:t.$t("setting.sv"),"fetching-data":i.formSubmitting&&i.redirect},null,8,["text","fetching-data"])])):d("",!0)],34)])],512)}const Y=B(K,[["render",T]]);export{Y as _};
