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 c,u as d,w as p,bw as N,b2 as w,eC as M}from"./outputWidgets.541a6a3f.js";import{a as T}from"./asyncComputed.6496ca6b.js";import{P as E}from"./project.99ccb1d4.js";import"./console.7080c244.js";import{M as B}from"./member.9b1db9b8.js";import{C as y}from"./gateway.647cec74.js";import{A as K}from"./activeRecord.867c40fa.js";import"./index.56c0102f.js";import{p as R}from"./icons.fbbc5318.js";import{_ as S}from"./CrudView.vue_vue_type_script_setup_true_lang.af69973c.js";import{f as U}from"./index.b048d0fb.js";import{A as V,a as z}from"./index.07910c0e.js";import{M as F}from"./Title.3011141f.js";import"./index.1b1480b6.js";import"./Form.2a9acb85.js";import"./index.7fb7f882.js";import"./index.33fb7a48.js";import"./index.5d5870f2.js";import"./dayjs.03d6e1d3.js";import"./index.f20ad580.js";import"./index.d89692b2.js";import"./TabPane.40396dd5.js";import"./index.ef35da09.js";import"./index.c3edc651.js";import"./index.dda022dd.js";import"./index.1797b918.js";import"./index.7f86f9a3.js";import"./index.68ffc7e6.js";import"./index.3cff0676.js";import"./pubsub.8482a29f.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]="ed4e4144-7ebd-46f5-a415-95a60525f879",r._sentryDebugIdIdentifier="sentry-dbid-ed4e4144-7ebd-46f5-a415-95a60525f879")}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"}],l=x().params.projectId,{loading:A,result:I,refetch:g}=T(async()=>Promise.all([s.list(l),E.get(l).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:l,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(l,n.id),g()}}]}]}}))!=null?o:[]}});return(a,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:p(()=>[]),default:p(()=>[c(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}),c(d(z),{code:"",copyable:""},{default:p(()=>[w(M(e.value),1)]),_:1})]),_:1},8,["open"])],64))}});export{be as default};
//# sourceMappingURL=ApiKeys.11408cb2.js.map
