var P=Object.defineProperty;var C=(r,e,t)=>e in r?P(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var u=(r,e,t)=>(C(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,bw as N,b2 as w,eC as M}from"./outputWidgets.eddbac36.js";import{a as T}from"./asyncComputed.fbd351ba.js";import{P as E}from"./project.d3d29cca.js";import"./console.56ba8e89.js";import{M as B}from"./member.d0083a24.js";import{C as y}from"./gateway.e4ec4a58.js";import{A as K}from"./activeRecord.64b754df.js";import"./index.c1e978a8.js";import{p as R}from"./icons.08aaa24c.js";import{_ as S}from"./CrudView.vue_vue_type_script_setup_true_lang.d009f8f3.js";import{f as U}from"./index.b048d0fb.js";import{A as V,a as z}from"./index.f428cf3a.js";import{M as F}from"./Title.7ca27be1.js";import"./index.cc18f239.js";import"./Form.f5163eed.js";import"./index.1a0ec4ff.js";import"./index.31447910.js";import"./index.9c583b89.js";import"./dayjs.d80a3524.js";import"./index.8318ec36.js";import"./index.8b693270.js";import"./TabPane.05333dfb.js";import"./index.b6a61078.js";import"./index.7a28d537.js";import"./index.d099a09e.js";import"./index.933610ff.js";import"./index.2c51d0a8.js";import"./index.b131e8f9.js";import"./index.3475d619.js";import"./pubsub.9aea5614.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]="99450f8f-1f9b-4299-8071-93c0c79ec890",r._sentryDebugIdIdentifier="sentry-dbid-99450f8f-1f9b-4299-8071-93c0c79ec890")}catch{}})();class G{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 G;class s{constructor(e){u(this,"record");this.record=K.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 be=_({__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)})))),b=async a=>{const o=await s.create({projectId:c,name:a.name});g(),e.value=o.value},v=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:U(n.createdAt,Date.now(),{addSuffix:!0})},{text:(h=i==null?void 0:i.email)!=null?h:"Unknown"},{text:"actions",actions:[{label:"Delete",icon:R,dangerous:!0,onClick:async()=>{await s.delete(c,n.id),g()}}]}]}}))!=null?o:[]}});return(a,o)=>($(),j(N,null,[l(S,{"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:v.value,fields:t,onCreate:b},null,8,["loading","table"]),l(d(F),{open:!!e.value,title:"Api key generated",onCancel:o[0]||(o[0]=n=>e.value=null)},{footer:p(()=>[]),default:p(()=>[l(d(V),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(z),{code:"",copyable:""},{default:p(()=>[w(M(e.value),1)]),_:1})]),_:1},8,["open"])],64))}});export{be as default};
//# sourceMappingURL=ApiKeys.624e0f47.js.map
