var C=Object.defineProperty;var P=(a,e,t)=>e in a?C(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 v,u as k,eq as x,bh as I,er as l,eA as D,eB as S,eC as j,t as B,ey as M,F as $,c as N,e as b,bu as E,bw as K}from"./registerWidgets.6f5be576.js";import{a as V}from"./asyncComputed.ea0bb8a8.js";import{P as z}from"./project.209725cf.js";import{C as g}from"./gateway.1c0effff.js";import{M as q}from"./member.dec8c29e.js";import{A as F}from"./activeRecord.eb203c6f.js";import"./index.1c2771c5.js";import{C as W}from"./CrudView.81000b9b.js";import{M as Y}from"./Modal.dd94f88f.js";import{q as G}from"./icons.b2622455.js";import{f as H}from"./index.b048d0fb.js";import"./passwordlessManager.1e2193ad.js";import"./pubsub.1dc45978.js";import"./storage.d8b26e7f.js";import"./DropdownMenu.ecdd2e52.js";import"./LoadingIndicator.2446cb23.js";import"./lottie.df73e4a1.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]="f88566fc-f8e2-411b-9a3a-83dc6c8c685c",a._sentryDebugIdIdentifier="sentry-dbid-f88566fc-f8e2-411b-9a3a-83dc6c8c685c")}catch{}})();class O{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 O;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 T=a=>(S("data-v-3da8363c"),a=a(),j(),a),U={class:"main-text"},J=T(()=>l("div",{class:"separator"},null,-1)),L=["value"],Q=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)=>(v(),k(Y,{ref_key:"modalRef",ref:t,"container-style":m,"header-style":y,"content-style":d},{header:x(()=>[I(" API Key Created ")]),content:x(()=>[l("div",U,[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),J,l("input",{disabled:"",value:n.value},null,8,L),l("div",{class:"buttons"},[l("button",{class:"cancel",onClick:p},"Close")])])]),_:1},512))}});const R=B(Q,[["__scopeId","data-v-3da8363c"]]),he=A({__name:"ApiKeys",setup(a){const e=[{key:"name",label:"API key name"}],n=M().params.projectId,{loading:m,result:y,refetch:d}=V(async()=>Promise.all([c.list(n),z.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:H(r.createdAt,Date.now(),{addSuffix:!0}),classes:[]},{text:(_=i==null?void 0:i.email)!=null?_:"Unknown"},{classes:["centered"],text:"actions",actions:[{label:"Delete",icon:G,dangerous:!0,onClick:async()=>{await c.delete(n,r.id),d()}}]}]}}))!=null?s:[]}});return(o,s)=>(v(),N(K,null,[b(W,{"entity-name":"API key","create-button-text":"Create API Key",loading:E(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"]),b(R)],64))}});export{he as default};
//# sourceMappingURL=ApiKeys.40432752.js.map
