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.153891cb.js";import{a as E}from"./asyncComputed.1c2e733f.js";import{G as P}from"./PhPencil.vue.a76c3b26.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.f4ff73cb.js";import{C as p}from"./router.579c91e6.js";import"./index.4ca46dd8.js";import{A as O,F as R}from"./Form.c8ea7c3d.js";import{A as q}from"./Text.b0ae0f80.js";import{M as z}from"./Modal.fb9d97fb.js";import"./DocsButton.vue_vue_type_script_setup_true_lang.273d3e2a.js";import"./BookOutlined.eb157924.js";import"./url.f4aa4fed.js";import"./Paragraph.0762ff9a.js";import"./Base.2cf6cca2.js";import"./index.38a388d2.js";import"./Title.8356c432.js";import"./index.72e9756f.js";import"./popupNotifcation.d7d31af4.js";import"./record.06ee4427.js";import"./pubsub.f8e50115.js";import"./hasIn.c05f2ad3.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]="50082823-919a-44bc-b310-43170f833edd",r._sentryDebugIdIdentifier="sentry-dbid-50082823-919a-44bc-b310-43170f833edd")}catch{}})();class L{constructor(){b(this,"urlPath","env-vars")}async create(e){return p.post(`projects/${e.projectId}/${this.urlPath}`,{name:e.name,value:e.value})}async delete(e,t){await p.delete(`projects/${e}/${this.urlPath}/${t}`)}async update(e,t,a){await p.patch(`projects/${e}/${this.urlPath}/${t}`,{value:a})}async list(e){return p.get(`projects/${e}/${this.urlPath}`)}async get(e){return p.get(`${this.urlPath}/${e}`)}}const c=new L;class i{constructor(e,t){this.projectId=e,this.dto=t}static async list(e){return(await c.list(e)).map(a=>new i(e,a))}static async create(e,t,a){const m=await c.create({projectId:e,name:t,value:a});return new i(e,m)}static async get(e,t){const a=await c.get(t);return new i(e,a)}get key(){return this.dto.name}async delete(){await c.delete(this.projectId,this.key)}async update(e){await c.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.41ddfc37.js.map
