import{_ as C}from"./CNIrc0EA.js";import{A as p}from"./AmaTRG5a.js";import{u as m}from"./7pZkuj9N.js";import{u as P}from"./BHvLfWtM.js";import{F as b}from"./DuSynPle.js";import{v as D}from"./B2895E6R.js";import{_ as h,c as o,o as s,b as a,e as _,f as c,t as v,D as f,F as y,G as F,I as A,r as j,g as q,d as k,h as z,w as R}from"./Bgmy51Qv.js";import{_ as U}from"./DIkWVjrx.js";import"./DuhDFJjj.js";const B={setup(){const{setRequest:e,deleteData:t}=m();return{setRequest:e,deleteData:t}},name:"PluginItem",data(){return{purchaseCode:null,deleting:!1,activated:!1,activating:!1}},components:{AjaxButton:p},props:{plugin:{type:Object}},methods:{async deletePlugin(){this.deleting=!0,await this.deleteData({params:this.plugin.id,api:"deletePlugin"}),this.deleting=!1,this.$emit("fetching-data")},async activatePlugin(){var n;this.activating=!0;const e=new FormData;e.append("name",(n=this.plugin)==null?void 0:n.name),e.append("code",this.purchaseCode);const t=await this.setRequest({params:e,api:"activatePlugin"});this.activating=!1,t&&!(t!=null&&t.status&&(t==null?void 0:t.status)===201)&&this.$emit("fetching-data",t)}}},E={class:"file-wrapper"},S={class:f("file-input has-file")},V=["placeholder"];function I(e,t,n,u,i,l){const r=p;return s(),o("div",E,[a("div",S,[t[1]||(t[1]=a("div",{class:"plus-wrap tick-wrap"},[a("i",{class:"icon tick-icon no-click"})],-1)),a("h6",null,v(n.plugin.name),1)]),n.plugin.active?_("",!0):(s(),o(y,{key:0},[F(a("input",{type:"text","onUpdate:modelValue":t[0]||(t[0]=d=>i.purchaseCode=d),placeholder:e.$t("dataPage.pkey")},null,8,V),[[A,i.purchaseCode]]),c(r,{class:"outline-btn",type:"button",disabled:i.activated,color:"primary",text:e.$t("dataPage.act"),"fetching-data":i.activating,onClicked:l.activatePlugin},null,8,["disabled","text","fetching-data","onClicked"])],64)),c(r,{class:"outline-btn",type:"button",color:"primary",text:e.$t("category.delete"),"fetching-data":i.deleting,onClicked:l.deletePlugin},null,8,["text","fetching-data","onClicked"])])}const M=h(B,[["render",I]]),N={setup(){const{setRequest:e,getRequest:t}=m();return{setRequest:e,getRequest:t}},name:"PluginsSetting",data(){return{result:null,file:null,loading:!1,fileUploading:!1,hasError:!1,fileAdded:!1}},props:{},mixins:[P,D],components:{PluginItem:M,AjaxButton:p,FileUpload:b},computed:{},methods:{activated(){setTimeout(()=>{window.location.reload(!0)},200)},async fetchAllPlugins(){this.loading=!0;try{const e=await this.getRequest({params:{},api:"allPlugins"});this.result=Object.assign({},e)}catch(e){z({statusCode:400,message:e.message})}this.loading=!1},fileChanged(e){const t=e.target.files[0];t&&(this.uploadMessage=this.isValidZip(t),this.uploadMessage||(this.file=t))},async uploadPlugin(){this.fileUploading=!0;const e=new FormData;e.append("file",this.file);const t=await this.setRequest({params:e,api:"uploadPlugin"});this.fileUploading=!1,t&&(this.fileAdded=!0,this.file=null,this.activated())}},created(){},async mounted(){await this.fetchAllPlugins()}},L={class:"plugins-wrap"},O={class:"dply-felx gap-15 f-wrap j-left align-start"},T={key:0,class:"plus-wrap tick-wrap"},G={key:1,class:"plus-wrap"},Z={key:2};function $(e,t,n,u,i,l){const r=C,d=j("plugin-item"),w=p;return s(),o("div",L,[c(r,{type:"zip"}),a("div",O,[(s(!0),o(y,null,q(i.result,(g,x)=>(s(),k(d,{key:x,plugin:g,onFetchingData:l.activated},null,8,["plugin","onFetchingData"]))),128)),a("div",{class:f(["file-wrapper",{"has-error":i.hasError}])},[a("div",{class:f(`file-input ${i.file&&"has-file"}`)},[a("input",{type:"file",accept:"zip,application/octet-stream,application/zip,application/x-zip,application/x-zip-compressed",onChange:t[0]||(t[0]=(...g)=>l.fileChanged&&l.fileChanged(...g)),ref:"pluginInput"},null,544),i.file?(s(),o("div",T,t[1]||(t[1]=[a("i",{class:"icon tick-icon no-click"},null,-1)]))):(s(),o("div",G,t[2]||(t[2]=[a("i",{class:"icon plus no-click"},null,-1)]))),i.file?(s(),o("h6",Z,v(i.file.name),1)):_("",!0)],2),c(w,{class:"outline-btn mb-10",type:"button",disabled:i.fileAdded,color:"primary",text:e.$t("ship.ap"),"fetching-data":i.fileUploading,onClicked:l.uploadPlugin},null,8,["disabled","text","fetching-data","onClicked"])],2)])])}const H=h(N,[["render",$]]),at={__name:"plugins",setup(e){return(t,n)=>{const u=H,i=U;return s(),k(i,{"active-route":"plugins",class:"mb-5"},{rightArea:R(()=>[c(u)]),_:1})}}};export{at as default};
