var C=Object.defineProperty;var P=(a,e,t)=>e in a?C(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var m=(a,e,t)=>(P(a,typeof e!="symbol"?e+"":e,t),t);import{d as k,r as x,ez as _,H as D,b as $,et as j,f as l,u as d,w as u,bf as N,aI as w,eB as M}from"./outputWidgets.a4629ff8.js";import{a as T}from"./asyncComputed.fb8b9ba6.js";import{P as B}from"./project.b861b2fe.js";import"./router.ab2ac3ba.js";import{M as E}from"./member.7e25c738.js";import{C as y}from"./gateway.68939de7.js";import{A as V}from"./activeRecord.a2b7d343.js";import"./columns.464a3bb5.js";import{k as z}from"./icons.73bff2ab.js";import{C as K}from"./CrudView.a5b1a4eb.js";import{f as R}from"./index.b048d0fb.js";import{A as S,a as U}from"./Text.eb216708.js";import{M as F}from"./Title.cf2a531e.js";import"./index.339c7421.js";import"./pubsub.25dc8c41.js";import"./index.f4ac7424.js";import"./Form.ab59726f.js";import"./url.d6a620b9.js";import"./index.874565bb.js";import"./index.48817ebe.js";import"./index.0f6dde5f.js";import"./index.46db6cb2.js";import"./index.56cfba6d.js";import"./index.fda4c602.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},e=new Error().stack;e&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[e]="1c558fbe-b5bf-46db-bb40-a79a0c377ab3",a._sentryDebugIdIdentifier="sentry-dbid-1c558fbe-b5bf-46db-bb40-a79a0c377ab3")}catch{}})();class G{constructor(){m(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 p=new G;class s{constructor(e){m(this,"record");this.record=V.create(p,e,"id")}static async list(e){return(await p.list(e)).map(f=>new s(f))}static async create(e){const t=await p.create(e);return new s(t)}static async delete(e,t){await p.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 fe=k({__name:"ApiKeys",setup(a){const e=x(null),t=[{key:"name",label:"API key name"}],c=_().params.projectId,{loading:b,result:I,refetch:g}=T(async()=>Promise.all([s.list(c),B.get(c).then(r=>E.list(r.organizationId))]).then(([r,o])=>r.map(n=>({apiKey:n,member:o.find(i=>i.authorId===n.ownerId)})))),A=async r=>{const o=await s.create({projectId:c,name:r.name});g(),e.value=o.value},v=D(()=>{var r,o;return{columns:[{name:"Name"},{name:"Creation date"},{name:"Owner"},{name:"Actions",align:"right"}],rows:(o=(r=I.value)==null?void 0:r.map(({apiKey:n,member:i})=>{var h;return{key:n.id,cells:[{text:n.name},{text:R(n.createdAt,Date.now(),{addSuffix:!0})},{text:(h=i==null?void 0:i.email)!=null?h:"Unknown"},{text:"actions",actions:[{label:"Delete",icon:z,dangerous:!0,onClick:async()=>{await s.delete(c,n.id),g()}}]}]}}))!=null?o:[]}});return(r,o)=>($(),j(N,null,[l(K,{"entity-name":"API key","create-button-text":"Create API Key",loading:d(b),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:A},null,8,["loading","table"]),l(d(F),{open:!!e.value,title:"Api key generated",onCancel:o[0]||(o[0]=n=>e.value=null)},{footer:u(()=>[]),default:u(()=>[l(d(S),null,{default:u(()=>[w("Your API key was successfully generated. Use this code to login on your local development environment or deploy using CI")]),_:1}),l(d(U),{code:"",copyable:""},{default:u(()=>[w(M(e.value),1)]),_:1})]),_:1},8,["open"])],64))}});export{fe as default};
//# sourceMappingURL=ApiKeys.5f93c828.js.map
