var k=Object.defineProperty;var b=(s,e,t)=>e in s?k(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var _=(s,e,t)=>(b(s,typeof e!="symbol"?e+"":e,t),t);import{d as C,r as w,b as P,t as S,w as x,S as A,x as l,N as j,O as M,Q as N,q as $,K as B,c as D,e as v,z as I,F as K,J as z}from"./registerWidgets.bb4c7eff.js";import{a as V}from"./asyncComputed.0adffaf6.js";import{P as E}from"./project.f812bab6.js";import{C as g}from"./gateway.99ed1590.js";import{M as F}from"./member.f9d3150c.js";import{A as O}from"./activeRecord.57c6bf02.js";import{C as W}from"./CrudView.74273abd.js";import{M as Y}from"./Modal.bf534f7d.js";import{v as q}from"./icons.e3de8035.js";import"./passwordlessManager.a806df6a.js";import"./DropdownMenu.45ad2be4.js";import"./CircularLoading.8dab92fc.js";class G{constructor(){_(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){_(this,"record");this.record=new O(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=s=>(M("data-v-3da8363c"),s=s(),N(),s),J={class:"main-text"},L=H(()=>l("div",{class:"separator"},null,-1)),Q=["value"],T=C({__name:"ApiKeyModal",emits:["delete"],setup(s,{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"},h=a=>{var o;n.value=a,(o=t==null?void 0:t.value)==null||o.open()},p=()=>{var a;return(a=t==null?void 0:t.value)==null?void 0:a.close()};return e({open:h,close:p}),(a,o)=>(P(),S(Y,{ref_key:"modalRef",ref:t,"container-style":m,"header-style":y,"content-style":d},{header:x(()=>[A(" API Key Created ")]),content:x(()=>[l("div",J,[A(j("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),L,l("input",{disabled:"",value:n.value},null,8,Q),l("div",{class:"buttons"},[l("button",{class:"cancel",onClick:p},"Close")])])]),_:1},512))}});const U=$(T,[["__scopeId","data-v-3da8363c"]]),de=C({__name:"ApiKeys",setup(s){const e=[{key:"name",label:"API key name"}],n=z().params.projectId,{loading:m,result:y,refetch:d}=V(async()=>Promise.all([c.list(n),E.get(n).then(a=>F.list(a.organizationId))]).then(([a,o])=>a.map(r=>({apiKey:r,member:o.find(i=>i.authorId===r.ownerId)})))),h=async a=>{const o=await c.create({projectId:n,name:a.name});d(),o.value&&prompt("Copy this API key and paste it in the local editor to deploy your app:",o==null?void 0:o.value)},p=B(()=>{var a,o;return{columns:[{name:"Name"},{name:"Creation date"},{name:"Owner"},{name:"Actions"}],rows:(o=(a=y.value)==null?void 0:a.map(({apiKey:r,member:i})=>{var f;return{key:r.id,cells:[{text:r.name,classes:["title","centered"]},{text:r.createdAt.toLocaleString(),classes:[]},{text:(f=i==null?void 0:i.email)!=null?f:"Unknown"},{classes:["centered"],text:"actions",actions:[{label:"Delete",icon:q,dangerous:!0,onClick:async()=>{await c.delete(n,r.id),d()}}]}]}}))!=null?o:[]}});return(a,o)=>(P(),D(K,null,[v(W,{"ask-name-on-create":!0,"entity-name":"API key","create-button-text":"Create API Key",loading:I(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:I(p),fields:e,onCreate:h},null,8,["loading","table"]),v(U)],64))}});export{de as default};
//# sourceMappingURL=ApiKeys.c70cd33c.js.map
