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.d2e5841c.js";import{a as P}from"./asyncComputed.e188c84d.js";import{G as _}from"./PhPencil.vue.ecceca31.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 p,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.abde7be7.js";import{C as c}from"./gateway.e5c93921.js";import"./index.2e366912.js";import{A as q,F as z}from"./Form.8489fb6d.js";import{M as H}from"./Modal.b9769244.js";import"./router.aff593c1.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.2107de83.js";import"./BookOutlined.ef6ccb36.js";import"./url.578d50c3.js";import"./index.42ebfb5e.js";import"./popupNotifcation.51a8836c.js";import"./record.4adc9d27.js";import"./pubsub.7f579dee.js";import"./hasIn.b8f131ab.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]="0e92ccce-d903-4619-a6d5-d510a9212b04",r._sentryDebugIdIdentifier="sentry-dbid-0e92ccce-d903-4619-a6d5-d510a9212b04")}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 d=new J;class i{constructor(e,t){this.projectId=e,this.dto=t}static async list(e){return(await d.list(e)).map(a=>new i(e,a))}static async create(e,t,a){const y=await d.create({projectId:e,name:t,value:a});return new i(e,y)}static async get(e,t){const a=await d.get(t);return new i(e,a)}get key(){return this.dto.name}async delete(){await d.delete(this.projectId,this.key)}async update(e){await d.update(this.projectId,this.key,e)}}const pe=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:p(()=>[a.value.type==="update-value"?(k(),T(l(z),{key:0,layout:"vertical"},{default:p(()=>[u(l(q),null,{default:p(()=>[u(l(S),null,{default:p(()=>[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{pe as default};
//# sourceMappingURL=EnvVars.f64641fb.js.map
