var x=Object.defineProperty;var A=(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)=>(A(r,typeof e!="symbol"?e+"":e,t),t);import{C as j}from"./CrudView.6cb8ad38.js";import{a as P}from"./asyncComputed.2a2a1288.js";import{G as _}from"./PhPencil.vue.0fcd0798.js";import{d as D,eG as G,r as E,y as U,b as k,ey as F,f as u,u as l,w as d,aG as N,eS as B,c as S,au as T,eJ as J,ct as K,eA as O}from"./outputWidgets.52571dac.js";import{C as c}from"./gateway.9b472f57.js";import"./index.803d0576.js";import{A as R,F as q}from"./Form.9e43a28b.js";import{A as z}from"./Text.0586c869.js";import{M as H}from"./Modal.514213ca.js";import"./router.0ae1ef4a.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.a5567333.js";import"./BookOutlined.7e4ac738.js";import"./url.5cc70021.js";import"./Paragraph.7aa2ce32.js";import"./Base.e64db743.js";import"./index.89edc4ba.js";import"./Title.8fbc2e7d.js";import"./index.f3e1df2a.js";import"./popupNotifcation.e85fac74.js";import"./record.2a93f29c.js";import"./pubsub.be7004e9.js";import"./hasIn.f1c353ba.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]="aaf28fb3-f792-47dd-b0fe-cc676551d231",r._sentryDebugIdIdentifier="sentry-dbid-aaf28fb3-f792-47dd-b0fe-cc676551d231")}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 we=D({__name:"EnvVars",setup(r){const t=G().params.projectId,a=E({type:"idle"}),{loading:m,result:y,refetch:f}=P(()=>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=U(()=>{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:_,label:"Update value",onClick(){$(o)}}]}]})))!=null?n:[]}});return(s,n)=>(k(),F(N,null,[u(j,{"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(H),{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(q),{key:0,layout:"vertical"},{default:d(()=>[u(l(R),null,{default:d(()=>[u(l(z),null,{default:d(()=>[T(J(a.value.key),1)]),_:1}),u(l(K),{value:a.value.newValue,"onUpdate:value":n[0]||(n[0]=o=>a.value.newValue=o)},null,8,["value"])]),_:1})]),_:1})):O("",!0)]),_:1},8,["open"])],64))}});export{we as default};
//# sourceMappingURL=EnvVars.840f0f2f.js.map
