var b=Object.defineProperty;var P=(a,e,t)=>e in a?b(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t;var h=(a,e,t)=>(P(a,typeof e!="symbol"?e+"":e,t),t);import{d as A,r as w,b as C,t as k,w as x,U as I,x as l,N as D,O as S,Q as j,q as M,J as N,K as $,c as B,e as v,z as K,F as z}from"./registerWidgets.cecc7add.js";import{a as E}from"./asyncComputed.08fdcc30.js";import{P as V}from"./project.14d2a965.js";import{C as g}from"./gateway.c00982e9.js";import{M as q}from"./member.dedd26d1.js";import{A as F}from"./activeRecord.2a9ab687.js";import"./index.d9da78e8.js";import{C as O}from"./CrudView.48449181.js";import{M as U}from"./Modal.4485a18b.js";import{q as W}from"./icons.a47594f6.js";import{f as Y}from"./index.b048d0fb.js";import"./passwordlessManager.8b0c672e.js";import"./pubsub.a43e35aa.js";import"./DropdownMenu.4df8c96d.js";import"./LoadingIndicator.06d4594a.js";import"./lottie.79ce2fdf.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]="89568fda-fc68-4614-a380-04f1c388928e",a._sentryDebugIdIdentifier="sentry-dbid-89568fda-fc68-4614-a380-04f1c388928e")}catch{}})();class G{constructor(){h(this,"urlPath","api-keys")}async create({projectId:e,name:t}){return g.post(`projects/${e}/${this.urlPath}`,{name:t})}async delete(e,t){await g.delete(`projects/${e}/${this.urlPath}/${t}`)}async list(e){return g.get(`projects/${e}/${this.urlPath}`)}async get(){throw new Error("Not implemented")}async update(){throw new Error("Not implemented")}}const u=new G;class c{constructor(e){h(this,"record");this.record=F.create(u,e,"id")}static async list(e){return(await u.list(e)).map(n=>new c(n))}static async create(e){const t=await u.create(e);return new c(t)}static async delete(e,t){await u.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 H=a=>(S("data-v-3da8363c"),a=a(),j(),a),J={class:"main-text"},Q=H(()=>l("div",{class:"separator"},null,-1)),T=["value"],L=A({__name:"ApiKeyModal",emits:["delete"],setup(a,{expose:e}){const t=w(null),n=w(""),m={maxWidth:"350px",height:"unset",padding:"30px"},y={display:"flex",flexDirection:"column",alignItems:"center",color:"#414A58",justifyContent:"center",lineHeight:"22px",fontSize:"18px",textAlign:"center",borderBottom:"none",gap:"23px",fontWeight:"700",marginBottom:"17px"},d={color:"#6D7C93",fontSize:"14px",textAlign:"center",justifyContent:"space-around"},f=o=>{var s;n.value=o,(s=t==null?void 0:t.value)==null||s.open()},p=()=>{var o;return(o=t==null?void 0:t.value)==null?void 0:o.close()};return e({open:f,close:p}),(o,s)=>(C(),k(U,{ref_key:"modalRef",ref:t,"container-style":m,"header-style":y,"content-style":d},{header:x(()=>[I(" API Key Created ")]),content:x(()=>[l("div",J,[I(D("Your API key has been created. Please copy it and store it in a safe place. You will not be able to see it again.")+" ",1),Q,l("input",{disabled:"",value:n.value},null,8,T),l("div",{class:"buttons"},[l("button",{class:"cancel",onClick:p},"Close")])])]),_:1},512))}});const R=M(L,[["__scopeId","data-v-3da8363c"]]),fe=A({__name:"ApiKeys",setup(a){const e=[{key:"name",label:"API key name"}],n=N().params.projectId,{loading:m,result:y,refetch:d}=E(async()=>Promise.all([c.list(n),V.get(n).then(o=>q.list(o.organizationId))]).then(([o,s])=>o.map(r=>({apiKey:r,member:s.find(i=>i.authorId===r.ownerId)})))),f=async o=>{const s=await c.create({projectId:n,name:o.name});d(),s.value&&prompt("Copy this API key and paste it in the local editor to deploy your app:",s==null?void 0:s.value)},p=$(()=>{var o,s;return{columns:[{name:"Name"},{name:"Creation date"},{name:"Owner"},{name:"Actions"}],rows:(s=(o=y.value)==null?void 0:o.map(({apiKey:r,member:i})=>{var _;return{key:r.id,cells:[{text:r.name,classes:["title","centered"]},{text:Y(r.createdAt,Date.now(),{addSuffix:!0}),classes:[]},{text:(_=i==null?void 0:i.email)!=null?_:"Unknown"},{classes:["centered"],text:"actions",actions:[{label:"Delete",icon:W,dangerous:!0,onClick:async()=>{await c.delete(n,r.id),d()}}]}]}}))!=null?s:[]}});return(o,s)=>(C(),B(z,null,[v(O,{"entity-name":"API key","create-button-text":"Create API Key",loading:K(m),title:"API Keys",description:"API Keys are used to deploy your app from the local editor.","empty-title":"No API keys here yet",table:p.value,fields:e,onCreate:f},null,8,["loading","table"]),v(R)],64))}});export{fe as default};
//# sourceMappingURL=ApiKeys.8022e7e4.js.map
