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.8a89e4ec.js";import{a as P}from"./asyncComputed.ce6d6eed.js";import{G as _}from"./PhPencil.vue.63507ef7.js";import{d as D,f1 as E,r as U,y as F,b as k,eV as G,f as u,u as l,w as d,ay as N,fd as B,c as T,cV as S,am as K,f4 as O,cs as R,eX as X}from"./outputWidgets.bff33647.js";import{C as c}from"./gateway.fd75c1ba.js";import"./index.b40d3bd7.js";import{A as q,F as z}from"./Form.70e7f6b0.js";import{M as H}from"./Modal.b7012161.js";import"./router.8006b2c4.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.2be6635f.js";import"./BookOutlined.62d0439b.js";import"./url.9e111d9b.js";import"./index.652b8bc4.js";import"./popupNotifcation.29ddd2ec.js";import"./record.29a71a1c.js";import"./pubsub.897f848f.js";import"./hasIn.edcda2a9.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]="ffe81448-3ea2-48fc-9b51-5a7bd6831226",r._sentryDebugIdIdentifier="sentry-dbid-ffe81448-3ea2-48fc-9b51-5a7bd6831226")}catch{}})();class J{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 J;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 y=await p.create({projectId:e,name:t,value:a});return new i(e,y)}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 de=D({__name:"EnvVars",setup(r){const t=E().params.projectId,a=U({type:"idle"}),{loading:y,result:m,refetch:f}=P(()=>i.list(t)),g=[{label:"Variable name",key:"key"},{label:"Variable value",key:"value",type:"multiline-text"}];async function h({key:o,value:n}){await i.create(t,o,n),f()}function $(o){a.value={type:"update-value",key:o.key,newValue:""}}async function v(o){var n;if(a.value.type==="update-value"&&o){const{key:s,newValue:C}=a.value,w=(n=m.value)==null?void 0:n.find(I=>I.key===s);w&&await w.update(C)}a.value={type:"idle"}}const V=F(()=>{var o,n;return{columns:[{name:"Key"},{name:"",align:"right"}],rows:(n=(o=m.value)==null?void 0:o.map(s=>({key:s.key,cells:[{type:"text",text:s.key},{type:"actions",actions:[{icon:B,label:"Delete",async onClick(){await s.delete(),f()},dangerous:!0},{icon:_,label:"Update value",onClick(){$(s)}}]}]})))!=null?n:[]}});return(o,n)=>(k(),G(N,null,[u(A,{"entity-name":"Env var",loading:l(y),title:"Environment Variables",description:"Set environment variables for your project.","empty-title":"No environment variables set",table:V.value,"create-button-text":"Add Environment Variable",fields:g,onCreate:h},null,8,["loading","table"]),u(l(H),{open:a.value.type==="update-value",title:"Update value",onCancel:n[1]||(n[1]=s=>v(!1)),onOk:n[2]||(n[2]=s=>v(!0))},{default:d(()=>[a.value.type==="update-value"?(k(),T(l(z),{key:0,layout:"vertical"},{default:d(()=>[u(l(q),null,{default:d(()=>[u(l(S),null,{default:d(()=>[K(O(a.value.key),1)]),_:1}),u(l(R),{value:a.value.newValue,"onUpdate:value":n[0]||(n[0]=s=>a.value.newValue=s)},null,8,["value"])]),_:1})]),_:1})):X("",!0)]),_:1},8,["open"])],64))}});export{de as default};
//# sourceMappingURL=EnvVars.0f897fac.js.map
