import{K as e,E as a,M as t,fF as s,_ as o,aC as l}from"./utils-lib.js?v=1761009159";import{c as r,g as n,e as m,U as d,v as c,N as i,y as p,r as u,x as v,B as f,Q as h,aC as y}from"./base-lib.js?v=1761009159";import{b as _,d as b,e as w,l as g,g as j,h as C}from"./form-item.js?v=1761009159";import{f as k}from"./validator.js?v=1761009159";import{B as x}from"./index115.js?v=1761009159";import{A as V}from"./add-compose.js?v=1761009159";import"./__commonjsHelpers__.js?v=1761009159";import"./index106.js?v=1761009159";import"./column.js?v=1761009159";import"./ace.js?v=1761009159";import"./useMethods.js?v=1761009159";const W=o(r({__name:"add-common",emits:["close","submit"],setup(o,{expose:l,emit:r}){const u=r,{BtForm:v,submit:f}=e({data:()=>({name:"",remark:"",data:"",env:"",save:!1,template:"",path:"",envpath:"",type:"data"}),options:e=>n(()=>[_("编排名称","name",{attrs:{placeholder:"请输入编排名称",class:"!w-[43.5rem]"},rules:[{required:!0,message:"请输入编排名称",trigger:["blur"]}]}),b([w("来源","type",[{label:"编辑",value:"data"},{label:"文件",value:"path"}],{attrs:{size:"default",onChange:()=>{}}})]),..."path"==e.value.type?[b([g(" ","path",{attrs:{class:"!w-[30rem]",placeholder:"请选择compose文件"}},()=>h(e,"compose")),j("本地上传",{attrs:{class:"!ml-[1rem]",onClick:()=>{S(e,"compose")}}})])]:[],C("compose内容",()=>m(x,{key:"editer1",class:"w-full h-[30rem]",modelValue:e.value.data,"onUpdate:modelValue":a=>e.value.data=a,editorOption:y},null),"data"),..."path"==e.value.type?[b([g(" ","envpath",{attrs:{class:"!w-[30rem]",placeholder:"请选择.env文件"}},()=>h(e,"env")),j("本地上传",{attrs:{class:"!ml-[1rem]",onClick:()=>{S(e,"env")}}})])]:[],C(".env内容",()=>m(x,{key:"editer2",class:"w-full h-[10rem]",modelValue:e.value.env,"onUpdate:modelValue":a=>e.value.env=a,editorOption:y},null),"data"),C("同时存为模板",()=>m(d,{modelValue:e.value.save,"onUpdate:modelValue":a=>e.value.save=a},null),"save"),...e.value.save?[_("模板名称","template",{attrs:{placeholder:"请输入模板名称",class:"!w-[43.5rem]"}}),_("备注","remark",{attrs:{placeholder:"备注",class:"!w-[43.5rem]"}})]:[]]),submit:async(e,a,t)=>{await a(),W(e)}}),h=(e,a)=>{k({type:"file",change:s=>{s&&("compose"==a&&(e.value.path=s),"env"==a&&(e.value.envpath=s),s.endsWith(".yml")||s.endsWith(".yaml")||"compose"!=a?s.endsWith(".env")||"env"!=a?V(s,e,a):t.error("请选择.env文件"):t.error("请选择compose文件"))}})},y={mode:"ace/mode/yaml",theme:a.value?"ace/theme/clouds_midnight":"ace/theme/chrome",wrap:!0,showInvisibles:!1,showFoldWidgets:!1,useSoftTabs:!0,tabSize:2,showPrintMargin:!1,readOnly:!1,fontSize:"12px"},V=async(e,a,t)=>{try{const{data:o}=await s({path:e});"object"==typeof o&&("compose"==t&&(a.value.data=o.data||""),"env"==t&&(a.value.env=o.data||""))}catch(o){}},W=async e=>{const a=e.value;let t={mod_name:"docker",sub_mod_name:"com",def_name:"create",project_name:a.name,config:a.data,env:a.env,add_template:a.save?1:0,remark:a.remark,ws_callback:"create"};a.save&&(t.template_name=a.template),u("submit",{params:t,close:()=>u("close")})},S=(e,a)=>{const s=document.createElement("input");s.type="file",s.style.display="none","compose"===a&&(s.accept=".yml,.yaml"),s.addEventListener("change",s=>{var o;const l=null==(o=s.target.files)?void 0:o[0];if(!l)return;if("compose"===a&&!l.name.endsWith(".yml")&&!l.name.endsWith(".yaml"))return void t.error("请选择compose文件");if("env"===a&&!l.name.endsWith("env"))return void t.error("请选择env文件");const r=new FileReader;r.onload=t=>{var s;const o=null==(s=t.target)?void 0:s.result;"compose"===a?(e.value.path=l.name,e.value.data=o):"env"===a&&(e.value.envpath=l.name,e.value.env=o)},r.onerror=()=>{t.error("读取文件内容失败")},r.readAsText(l)}),document.body.appendChild(s),s.click(),setTimeout(()=>{document.body.removeChild(s)},0)};return l({onConfirm:f}),(e,a)=>(c(),i(p(v),{class:"p-[1.6rem]"}))}}),[["__scopeId","data-v-3d5c7932"]]),S={class:"flex flex-col p-[16px] lib-box"},U=o(r({__name:"index",props:{compData:{default:()=>({})}},emits:["close"],setup(e,{expose:a,emit:t}){const s=t,o=u("first"),r=u(),n=u(),d=()=>{s("close")};return a({onConfirm:async()=>{try{"first"==o.value?r.value.onConfirm():n.value.onConfirm()}catch(e){}}}),(e,a)=>{const t=y,s=l;return c(),v("div",S,[m(s,{type:"card",modelValue:p(o),"onUpdate:modelValue":a[0]||(a[0]=e=>h(o)?o.value=e:null)},{default:f(()=>[m(t,{label:"常规创建",name:"first"},{default:f(()=>[m(W,{ref_key:"first",ref:r,onClose:d,onSubmit:e.compData.wsConfirm},null,8,["onSubmit"])]),_:1}),m(t,{label:"使用模板",name:"second"},{default:f(()=>[m(V,{ref_key:"second",ref:n,onClose:d},null,512)]),_:1})]),_:1},8,["modelValue"])])}}}),[["__scopeId","data-v-0a1696c8"]]);export{U as default};
