var P=Object.defineProperty;var C=(a,e,t)=>e in a?P(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var m=(a,e,t)=>(C(a,typeof e!="symbol"?e+"":e,t),t);import{d as _,r as k,ey as x,H as D,b as $,er as j,f as c,u as d,w as u,bu as N,b0 as w,eA as M}from"./registerWidgets.4340e287.js";import{a as T}from"./asyncComputed.a4cc4ebe.js";import{P as E}from"./project.9f1727ca.js";import{C as y}from"./gateway.1f2ccdb0.js";import{M as B}from"./member.02e55f2a.js";import{A as K}from"./activeRecord.c40ac301.js";import"./index.dbce76fa.js";import{p as R}from"./icons.da02f7f7.js";import{_ as S}from"./CrudView.vue_vue_type_script_setup_true_lang.e9f57b5e.js";import{f as U}from"./index.b048d0fb.js";import{A as V,a as z}from"./index.f58e2ef8.js";import{M as F}from"./Title.4165770a.js";import"./passwordlessManager.8c70219b.js";import"./pubsub.3290d859.js";import"./storage.dfe55847.js";import"./Form.7b78c348.js";import"./index.17a2edf7.js";import"./index.7bc7e814.js";import"./index.d24f6130.js";import"./index.9aade351.js";import"./index.c13b703c.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]="e0d4a624-ac60-4217-b968-024594fd3646",a._sentryDebugIdIdentifier="sentry-dbid-e0d4a624-ac60-4217-b968-024594fd3646")}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=K.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 pe=_({__name:"ApiKeys",setup(a){const e=k(null),t=[{key:"name",label:"API key name"}],l=x().params.projectId,{loading:A,result:I,refetch:g}=T(async()=>Promise.all([s.list(l),E.get(l).then(r=>B.list(r.organizationId))]).then(([r,o])=>r.map(n=>({apiKey:n,member:o.find(i=>i.authorId===n.ownerId)})))),b=async r=>{const o=await s.create({projectId:l,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: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(l,n.id),g()}}]}]}}))!=null?o:[]}});return(r,o)=>($(),j(N,null,[c(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"]),c(d(F),{open:!!e.value,title:"Api key generated",onCancel:o[0]||(o[0]=n=>e.value=null)},{footer:u(()=>[]),default:u(()=>[c(d(V),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}),c(d(z),{code:"",copyable:""},{default:u(()=>[w(M(e.value),1)]),_:1})]),_:1},8,["open"])],64))}});export{pe as default};
//# sourceMappingURL=ApiKeys.f624c74a.js.map
