var x=Object.defineProperty;var j=(r,e,t)=>e in r?x(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var b=(r,e,t)=>(j(r,typeof e!="symbol"?e+"":e,t),t);import{C as A}from"./CrudView.b9ba563d.js";import{a as E}from"./asyncComputed.b227690c.js";import{G as P}from"./PhPencil.vue.e931b93e.js";import{d as _,eE as D,r as U,J as F,b as k,ew as G,f as u,u as l,w as d,aE as N,eS as B,c as S,as as T,eH as H,cr as J,ey as K}from"./outputWidgets.2c936b33.js";import{C as c}from"./router.9a76cc66.js";import"./index.bd2be0a2.js";import{A as O,F as R}from"./Form.b5e24132.js";import{A as q}from"./Text.a2f30647.js";import{M as z}from"./Modal.17cdde78.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.dd7fbd1a.js";import"./BookOutlined.31cb7ffb.js";import"./url.a282f1d5.js";import"./Paragraph.51f31516.js";import"./Base.7b44942c.js";import"./index.18754ce2.js";import"./Title.6affb5db.js";import"./index.f0d39170.js";import"./popupNotifcation.a42892dc.js";import"./record.210736c4.js";import"./pubsub.4c454988.js";import"./hasIn.85b27717.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[e]="bdca9d12-c6e4-4354-a980-b8da277fe1c8",r._sentryDebugIdIdentifier="sentry-dbid-bdca9d12-c6e4-4354-a980-b8da277fe1c8")}catch{}})();class L{constructor(){b(this,"urlPath","env-vars")}async create(e){return c.post(`projects/${e.projectId}/${this.urlPath}`,{name:e.name,value:e.value})}async delete(e,t){await c.delete(`projects/${e}/${this.urlPath}/${t}`)}async update(e,t,a){await c.patch(`projects/${e}/${this.urlPath}/${t}`,{value:a})}async list(e){return c.get(`projects/${e}/${this.urlPath}`)}async get(e){return c.get(`${this.urlPath}/${e}`)}}const p=new L;class i{constructor(e,t){this.projectId=e,this.dto=t}static async list(e){return(await p.list(e)).map(a=>new i(e,a))}static async create(e,t,a){const m=await p.create({projectId:e,name:t,value:a});return new i(e,m)}static async get(e,t){const a=await p.get(t);return new i(e,a)}get key(){return this.dto.name}async delete(){await p.delete(this.projectId,this.key)}async update(e){await p.update(this.projectId,this.key,e)}}const ve=_({__name:"EnvVars",setup(r){const t=D().params.projectId,a=U({type:"idle"}),{loading:m,result:y,refetch:f}=E(()=>i.list(t)),g=[{label:"Variable name",key:"key"},{label:"Variable value",key:"value",type:"multiline-text"}];async function h({key:s,value:n}){await i.create(t,s,n),f()}function $(s){a.value={type:"update-value",key:s.key,newValue:""}}async function v(s){var n;if(a.value.type==="update-value"&&s){const{key:o,newValue:V}=a.value,w=(n=y.value)==null?void 0:n.find(I=>I.key===o);w&&await w.update(V)}a.value={type:"idle"}}const C=F(()=>{var s,n;return{columns:[{name:"Key"},{name:"",align:"right"}],rows:(n=(s=y.value)==null?void 0:s.map(o=>({key:o.key,cells:[{type:"text",text:o.key},{type:"actions",actions:[{icon:B,label:"Delete",async onClick(){await o.delete(),f()},dangerous:!0},{icon:P,label:"Update value",onClick(){$(o)}}]}]})))!=null?n:[]}});return(s,n)=>(k(),G(N,null,[u(A,{"entity-name":"Env var",loading:l(m),title:"Environment Variables",description:"Set environment variables for your project.","empty-title":"No environment variables set",table:C.value,"create-button-text":"Add Environment Variable",fields:g,onCreate:h},null,8,["loading","table"]),u(l(z),{open:a.value.type==="update-value",title:"Update value",onCancel:n[1]||(n[1]=o=>v(!1)),onOk:n[2]||(n[2]=o=>v(!0))},{default:d(()=>[a.value.type==="update-value"?(k(),S(l(R),{key:0,layout:"vertical"},{default:d(()=>[u(l(O),null,{default:d(()=>[u(l(q),null,{default:d(()=>[T(H(a.value.key),1)]),_:1}),u(l(J),{value:a.value.newValue,"onUpdate:value":n[0]||(n[0]=o=>a.value.newValue=o)},null,8,["value"])]),_:1})]),_:1})):K("",!0)]),_:1},8,["open"])],64))}});export{ve as default};
//# sourceMappingURL=EnvVars.49265139.js.map
