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 u=(a,e,t)=>(C(a,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.1f391ab3.js";import{a as T}from"./asyncComputed.56fb497e.js";import{P as E}from"./project.76ccde49.js";import"./console.3edc9cde.js";import{M as B}from"./member.57ba8d70.js";import{C as y}from"./gateway.98993b50.js";import{A as J}from"./activeRecord.b9964a93.js";import"./index.e8fb5940.js";import{q as K}from"./icons.35fd2af6.js";import{_ as R}from"./CrudView.vue_vue_type_script_setup_true_lang.fc3376a4.js";import{f as S}from"./index.b048d0fb.js";import{A as U,a as V}from"./index.6e066317.js";import{M as q}from"./Title.e19c9b7e.js";import"./index.a24e4cfd.js";import"./Form.d88e907e.js";import"./CollapsePanel.ed22c9ce.js";import"./index.3daa08be.js";import"./index.beaf06d8.js";import"./index.16917afa.js";import"./dayjs.12321a58.js";import"./index.06f9a351.js";import"./index.130e9d58.js";import"./TabPane.49afc3f4.js";import"./index.a2705008.js";import"./index.257ed691.js";import"./index.72e9f57c.js";import"./index.4260e6cf.js";import"./index.f0baefdd.js";import"./index.37b8f4ea.js";import"./index.18aa8459.js";import"./index.d09067f1.js";import"./pubsub.ab26e051.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]="64728f3c-6a72-4e3f-a7e0-f43c6b4aee6a",a._sentryDebugIdIdentifier="sentry-dbid-64728f3c-6a72-4e3f-a7e0-f43c6b4aee6a")}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 Pe=_({__name:"ApiKeys",setup(a){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(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: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: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(r,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:v.value,fields:t,onCreate:b},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{Pe as default};
//# sourceMappingURL=ApiKeys.7a8757d4.js.map
