var C=Object.defineProperty;var b=(r,e,t)=>e in r?C(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var u=(r,e,t)=>(b(r,typeof e!="symbol"?e+"":e,t),t);import{d as _,r as k,eA as x,J as D,b as $,et as j,f as l,u as d,w as p,bg as N,aJ as w,eC as M}from"./outputWidgets.c072fe4e.js";import{a as T}from"./asyncComputed.376cdc00.js";import{P as E}from"./project.5033d689.js";import"./console.a87f2a82.js";import{M as B}from"./member.78d15ad7.js";import{C as y}from"./gateway.18ca6e0a.js";import{A as J}from"./activeRecord.fdc25b97.js";import"./index.90440471.js";import{q as K}from"./icons.158b4825.js";import{_ as R}from"./CrudView.vue_vue_type_script_setup_true_lang.9296340f.js";import{f as S}from"./index.b048d0fb.js";import{A as U,a as V}from"./index.4cff163b.js";import{M as q}from"./Title.e3dcb8ea.js";import"./index.00103e26.js";import"./Form.9f52866c.js";import"./CollapsePanel.ecfd8c73.js";import"./index.d808811c.js";import"./index.ec8e038a.js";import"./index.dce83dc7.js";import"./dayjs.a56ae918.js";import"./index.4e6af937.js";import"./index.8ab39784.js";import"./TabPane.df5f41ca.js";import"./index.c5fd7926.js";import"./index.148bcdd7.js";import"./index.d9c3e0de.js";import"./index.e5a5efcd.js";import"./index.e7c5574b.js";import"./index.96de14c0.js";import"./index.28ce0851.js";import"./index.2e3640f1.js";import"./pubsub.98ad9fe0.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]="f8c49e23-59c7-427e-a1fa-4fd885610813",r._sentryDebugIdIdentifier="sentry-dbid-f8c49e23-59c7-427e-a1fa-4fd885610813")}catch{}})();class z{constructor(){u(this,"urlPath","api-keys")}async create({projectId:e,name:t}){return y.post(`projects/${e}/${this.urlPath}`,{name:t})}async delete(e,t){await y.delete(`projects/${e}/${this.urlPath}/${t}`)}async list(e){return y.get(`projects/${e}/${this.urlPath}`)}async get(){throw new Error("Not implemented")}async update(){throw new Error("Not implemented")}}const m=new z;class s{constructor(e){u(this,"record");this.record=J.create(m,e,"id")}static async list(e){return(await m.list(e)).map(f=>new s(f))}static async create(e){const t=await m.create(e);return new s(t)}static async delete(e,t){await m.delete(e,t)}get id(){return this.record.get("id")}get name(){return this.record.get("name")}async save(){await this.record.save()}get createdAt(){return new Date(this.record.get("createdAt"))}hasChanges(){return this.record.hasChanges()}get ownerId(){return this.record.get("createdBy")}get value(){var e;return(e=this.record.get("value"))!=null?e:null}}const Ce=_({__name:"ApiKeys",setup(r){const e=k(null),t=[{key:"name",label:"API key name"}],c=x().params.projectId,{loading:A,result:I,refetch:g}=T(async()=>Promise.all([s.list(c),E.get(c).then(a=>B.list(a.organizationId))]).then(([a,o])=>a.map(n=>({apiKey:n,member:o.find(i=>i.authorId===n.ownerId)})))),v=async a=>{const o=await s.create({projectId:c,name:a.name});g(),e.value=o.value},P=D(()=>{var a,o;return{columns:[{name:"Name"},{name:"Creation date"},{name:"Owner"},{name:"Actions",align:"right"}],rows:(o=(a=I.value)==null?void 0:a.map(({apiKey:n,member:i})=>{var h;return{key:n.id,cells:[{text:n.name},{text:S(n.createdAt,Date.now(),{addSuffix:!0})},{text:(h=i==null?void 0:i.email)!=null?h:"Unknown"},{text:"actions",actions:[{label:"Delete",icon:K,dangerous:!0,onClick:async()=>{await s.delete(c,n.id),g()}}]}]}}))!=null?o:[]}});return(a,o)=>($(),j(N,null,[l(R,{"entity-name":"API key","create-button-text":"Create API Key",loading:d(A),title:"API Keys",description:"API Keys are used to deploy your app from the local editor.","empty-title":"No API keys here yet",table:P.value,fields:t,onCreate:v},null,8,["loading","table"]),l(d(q),{open:!!e.value,title:"Api key generated",onCancel:o[0]||(o[0]=n=>e.value=null)},{footer:p(()=>[]),default:p(()=>[l(d(U),null,{default:p(()=>[w("Your API key was successfully generated. Use this code to login on your local development environment or deploy using CI")]),_:1}),l(d(V),{code:"",copyable:""},{default:p(()=>[w(M(e.value),1)]),_:1})]),_:1},8,["open"])],64))}});export{Ce as default};
//# sourceMappingURL=ApiKeys.0aea6086.js.map
