import{a as d,c as F,j as e}from"./vendor-react-YMhRUmcb.js";import{g as M,d as S,B as g,l as k,i as f,m as O,C as P}from"./index-D2uzyr9g.js";import{S as _}from"./StatCard-Xzk79Siz.js";import{I as G}from"./input-DL1WY4HG.js";import{ar as E,X as B,i as C,C as V,g as R,A as H,R as J,b7 as W,aa as X,aW as K,b1 as Y,az as q,aM as Q,T as A}from"./vendor-icons-DINCNwpk.js";import{w as Z}from"./webhookService-BUZkpEvD.js";import{T as ee,a as te,b as U,c as D}from"./Tabs-C8UCeQNW.js";import{X as se}from"./vendor-fFnFILYR.js";import"./vendor-router-DX94Iu-2.js";import"./vendor-tanstack-CoFNL2zy.js";import"./vendor-utils-4BWoYre8.js";const ae=[{id:"user.read",label:"Read User Data"},{id:"user.write",label:"Update User Profile"},{id:"tracks.read",label:"Read Tracks"},{id:"tracks.upload",label:"Upload Tracks"},{id:"sales.read",label:"Read Sales Data"}],oe=({onClose:t,onCreate:n})=>{const a=M(),[o,h]=d.useState(1),[x,m]=d.useState(""),[l,u]=d.useState(["user.read"]),[b,w]=d.useState(""),[i,s]=d.useState(!1),[c,j]=d.useState(!1);d.useEffect(()=>(j(!0),()=>j(!1)),[]);const z=r=>{u(p=>p.includes(r)?p.filter(N=>N!==r):[...p,r])},L=async r=>{if(r?.preventDefault(),r?.stopPropagation(),!x.trim()){a.error("Please enter a name for your API key");return}if(l.length===0){a.error("Please select at least one permission scope");return}s(!0);try{const p=await n({name:x.trim(),scopes:l});if(p.key)w(p.key);else{const N=`vz_${Math.random().toString(36).substr(2,8)}_${Math.random().toString(36).substr(2,16)}`;w(N)}h(2),s(!1)}catch(p){throw s(!1),p}},$=()=>{navigator.clipboard.writeText(b),a.success("API Key copied to clipboard")};return c?F.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center p-4",style:{zIndex:9999},children:[e.jsx("div",{className:"absolute inset-0 bg-kodo-void/90 backdrop-blur-md",onClick:o===1?t:void 0}),e.jsxs("div",{className:"relative w-full max-w-2xl bg-kodo-graphite border border-kodo-steel rounded-xl shadow-2xl animate-scaleIn overflow-hidden glass-hud flex flex-col max-h-[85vh]",children:[e.jsxs("div",{className:"p-6 border-b border-kodo-steel/50 flex justify-between items-center bg-white/5 flex-none z-10",children:[e.jsxs("h3",{className:"text-xl font-bold text-white flex items-center gap-3 font-display",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-kodo-gold/20 flex items-center justify-center border border-kodo-gold/30",children:e.jsx(E,{className:"w-5 h-5 text-kodo-gold"})}),o===1?"Create API Key":"API Key Generated"]}),e.jsx("button",{onClick:t,className:"p-2 hover:bg-white/10 rounded-lg transition-colors",children:e.jsx(B,{className:"w-5 h-5 text-kodo-content-dim hover:text-white"})})]}),e.jsx("div",{className:"p-8 overflow-y-auto custom-scrollbar flex-1 relative",children:o===1?e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-kodo-secondary uppercase tracking-wider mb-3",children:"Key Name"}),e.jsx(G,{placeholder:"e.g. Production Server, Mobile App",value:x,onChange:r=>m(r.target.value),autoFocus:!0,disabled:i,className:"bg-kodo-void/50 border-kodo-steel focus:border-kodo-cyan h-12 text-lg w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-kodo-secondary uppercase tracking-wider mb-4",children:"Permissions (Scopes)"}),e.jsx("div",{className:"grid grid-cols-1 gap-3",children:ae.map(r=>e.jsxs("label",{className:S("flex items-center justify-between p-4 rounded-xl border cursor-pointer transition-all duration-200 group relative overflow-hidden",l.includes(r.id)?"bg-kodo-cyan/10 border-kodo-cyan/50 shadow-[0_0_15px_rgba(102,252,241,0.1)]":"bg-kodo-void/30 border-kodo-steel/50 hover:border-kodo-steel hover:bg-white/5"),children:[e.jsxs("div",{className:"flex items-center gap-4 z-10 relative",children:[e.jsx("div",{className:S("w-5 h-5 rounded border flex items-center justify-center transition-colors flex-none",l.includes(r.id)?"bg-kodo-cyan border-kodo-cyan":"border-kodo-steel group-hover:border-kodo-content-dim"),children:l.includes(r.id)&&e.jsx(C,{className:"w-3 h-3 text-black"})}),e.jsx("span",{className:S("text-sm font-medium transition-colors",l.includes(r.id)?"text-white":"text-kodo-content-dim group-hover:text-kodo-text-main"),children:r.label})]}),e.jsx("div",{className:"text-xs font-mono text-kodo-steel z-10 hidden sm:block opacity-60 relative",children:r.id}),e.jsx("input",{type:"checkbox",className:"hidden",checked:l.includes(r.id),onChange:()=>z(r.id)})]},r.id))})]})]}):e.jsxs("div",{className:"text-center space-y-8 py-4",children:[e.jsxs("div",{className:"relative w-20 h-20 mx-auto",children:[e.jsx("div",{className:"absolute inset-0 bg-kodo-lime/20 rounded-full animate-ping opacity-50"}),e.jsx("div",{className:"relative w-full h-full bg-gradient-to-br from-kodo-lime/20 to-kodo-cyan/20 rounded-full flex items-center justify-center border border-kodo-lime/30 shadow-[0_0_30px_rgba(54,229,209,0.2)]",children:e.jsx(C,{className:"w-10 h-10 text-kodo-lime drop-shadow-[0_0_10px_rgba(54,229,209,0.5)]"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-2xl font-bold text-white font-display",children:"Key Created Successfully"}),e.jsx("p",{className:"text-sm text-kodo-content-dim max-w-xs mx-auto leading-relaxed",children:"Please copy your API key now. For security reasons, it cannot be displayed again properly."})]}),e.jsxs("div",{className:"bg-black/40 border border-kodo-steel/50 rounded-xl p-1 flex items-center gap-2 relative group overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-r from-transparent via-white/5 to-transparent skew-x-12 translate-x-[-200%] group-hover:animate-shimmer"}),e.jsx("div",{className:"flex-1 px-4 py-3 font-mono text-sm text-kodo-gold overflow-x-auto no-scrollbar whitespace-nowrap text-left",children:b}),e.jsx(g,{variant:"ghost",size:"icon",onClick:$,className:"h-10 w-10 text-kodo-content-dim hover:text-white hover:bg-white/10 rounded-lg hover:scale-105 transition-all flex-none",title:"Copy to clipboard",children:e.jsx(V,{className:"w-5 h-5"})})]})]})}),e.jsx("div",{className:"p-6 border-t border-kodo-steel/50 bg-white/5 flex justify-end gap-3 backdrop-blur-sm flex-none z-10 transition-colors",children:o===1?e.jsxs(e.Fragment,{children:[e.jsx(g,{variant:"ghost",onClick:t,disabled:i,className:"hover:bg-white/10 text-kodo-content-dim hover:text-white",children:"Cancel"}),e.jsx(g,{variant:"default",onClick:r=>{r.preventDefault(),r.stopPropagation(),L(r)},disabled:i||!x.trim()||l.length===0,type:"button",className:"bg-kodo-cyan hover:bg-kodo-cyan/80 text-black font-semibold shadow-[0_0_20px_rgba(102,252,241,0.3)] hover:shadow-[0_0_30px_rgba(102,252,241,0.5)] transition-all duration-300",children:i?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"w-4 h-4 mr-2 animate-spin"}),"Generating..."]}):"Generate Key"})]}):e.jsx(g,{onClick:t,className:"bg-kodo-cyan hover:bg-kodo-cyan/80 text-black font-semibold min-w-[100px] shadow-[0_0_20px_rgba(102,252,241,0.3)] hover:shadow-[0_0_30px_rgba(102,252,241,0.5)] transition-all duration-300",children:"Done"})})]})]}),document.body):null},T="veza_dev_api_keys",v=()=>{const t=localStorage.getItem(T);return t?JSON.parse(t):[]},I=t=>{localStorage.setItem(T,JSON.stringify(t))},y={listKeys:async()=>(await new Promise(t=>setTimeout(t,300)),v()),createKey:async t=>{await new Promise(b=>setTimeout(b,600));const n=Math.random().toString(36).substr(2,8),a=Math.random().toString(36).substr(2,16),o=`vz_${n}_${a}`,h=`vz_${n}...`,m=new Date().toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),l={id:`k-${Date.now()}`,name:t.name,prefix:h,created:m,lastUsed:"Never",status:"active",scopes:t.scopes,key:o},u=v();return I([l,...u]),l},revokeKey:async t=>{await new Promise(o=>setTimeout(o,300));const a=v().map(o=>o.id===t?{...o,status:"revoked"}:o);return I(a),{success:!0}},deleteKey:async t=>{const n=v();I(n.filter(a=>a.id!==t))},getStats:async()=>{const n=v().filter(o=>o.status==="active").length;let a=0;try{a=(await Z.list()).length}catch(o){console.error("Failed to fetch webhook stats",o)}return{requests_24h:145200+a*1240,avg_latency:45,active_keys:n,active_webhooks:a}}};function re({specUrl:t,spec:n,useIframe:a=!1}){const o=d.useRef(null),h=d.useRef(null),[x,m]=d.useState(null),l=()=>{if(t)return t;const s=(f.API_URL.startsWith("http")?f.API_URL:`${window.location.origin}${f.API_URL}`).replace(/\/api\/v1$/,"");return a?`${s}/swagger/index.html`:`${s}/swagger/doc.json`},u=()=>`${(f.API_URL.startsWith("http")?f.API_URL:`${window.location.origin}${f.API_URL}`).replace(/\/api\/v1$/,"")}/swagger/index.html`;d.useEffect(()=>{o.current&&k.debug("Swagger UI initialized",{specUrl:t||l(),hasSpec:!!n,useIframe:a})},[t,n,a]);const b={url:n?void 0:l(),spec:n,deepLinking:!0,displayOperationId:!1,defaultModelsExpandDepth:1,defaultModelExpandDepth:1,docExpansion:"list",filter:!0,showExtensions:!0,showCommonExtensions:!0,tryItOutEnabled:!0,supportedSubmitMethods:["get","post","put","delete","patch"],requestInterceptor:i=>{const s=localStorage.getItem("access_token");s&&i.headers&&(i.headers.Authorization=`Bearer ${s}`);const c=localStorage.getItem("csrf_token");return c&&i.headers&&(i.headers["X-CSRF-Token"]=c),i},onComplete:()=>{m(null),k.debug("Swagger UI loaded successfully",{url:l()})},onFailure:i=>{m(i.message||"Failed to load Swagger documentation"),k.error("Failed to load Swagger UI",{error:i.message,stack:i.stack,url:l()})}},w=()=>{m(null),window.location.reload()};if(a)return e.jsx("div",{ref:o,className:"swagger-ui-container",style:{height:"100%",minHeight:"600px"},children:e.jsx("iframe",{ref:h,src:u(),className:"w-full h-full border-0 rounded-lg",style:{minHeight:"600px"},title:"Swagger UI Documentation",onLoad:()=>{k.debug("Swagger UI iframe loaded successfully"),m(null)},onError:()=>{m("Failed to load Swagger UI in iframe"),k.error("Failed to load Swagger UI iframe")}})});if(x){const i=u();return e.jsxs("div",{className:"flex flex-col items-center justify-center p-12 min-h-[600px]",children:[e.jsx(H,{className:"w-16 h-16 text-kodo-red mb-4"}),e.jsx("h3",{className:"text-xl font-bold text-white mb-2",children:"Failed to Load API Documentation"}),e.jsx("p",{className:"text-sm text-kodo-secondary mb-4 text-center max-w-md",children:x}),e.jsxs("p",{className:"text-xs text-kodo-content-dim mb-6 text-center max-w-md",children:["Trying to load from: ",l(),e.jsx("br",{}),e.jsx("span",{className:"text-kodo-steel",children:"The Swagger JSON endpoint may not be available. Try opening Swagger UI directly."})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsxs(g,{onClick:w,variant:"default",children:[e.jsx(J,{className:"w-4 h-4 mr-2"}),"Retry"]}),e.jsx(g,{onClick:()=>window.open(i,"_blank"),variant:"outline",children:"Open Swagger UI"}),e.jsx(g,{onClick:()=>{window.location.reload()},variant:"outline",children:"Use Iframe Mode"})]})]})}return e.jsxs("div",{ref:o,className:"swagger-ui-container",style:{height:"100%",minHeight:"600px"},children:[e.jsx("style",{children:` .swagger-ui-container .swagger-ui { background: transparent; } .swagger-ui-container .swagger-ui .topbar { display: none; } .swagger-ui-container .swagger-ui .info { margin: 20px 0; } .swagger-ui-container .swagger-ui .info .title { color: #fff; } .swagger-ui-container .swagger-ui .scheme-container { background: rgba(255, 255, 255, 0.05); padding: 10px; border-radius: 8px; margin: 20px 0; } .swagger-ui-container .swagger-ui .opblock { background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 8px; margin: 10px 0; } .swagger-ui-container .swagger-ui .opblock.opblock-post { border-color: rgba(102, 252, 241, 0.3); } .swagger-ui-container .swagger-ui .opblock.opblock-get { border-color: rgba(102, 252, 241, 0.3); } .swagger-ui-container .swagger-ui .opblock.opblock-put { border-color: rgba(255, 193, 7, 0.3); } .swagger-ui-container .swagger-ui .opblock.opblock-delete { border-color: rgba(244, 67, 54, 0.3); } .swagger-ui-container .swagger-ui .opblock .opblock-summary { color: #fff; } .swagger-ui-container .swagger-ui .opblock .opblock-description-wrapper { color: rgba(255, 255, 255, 0.8); } .swagger-ui-container .swagger-ui .parameter__name { color: #66fcf1; } .swagger-ui-container .swagger-ui .response-col_status { color: #fff; } .swagger-ui-container .swagger-ui .response-col_description { color: rgba(255, 255, 255, 0.8); } .swagger-ui-container .swagger-ui input, .swagger-ui-container .swagger-ui select, .swagger-ui-container .swagger-ui textarea { background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); color: #fff; } .swagger-ui-container .swagger-ui .btn { background: #66fcf1; color: #000; border: none; } .swagger-ui-container .swagger-ui .btn:hover { background: #52e8e0; } .swagger-ui-container .swagger-ui .btn.execute { background: #66fcf1; color: #000; } .swagger-ui-container .swagger-ui .btn.cancel { background: rgba(255, 255, 255, 0.1); color: #fff; } `}),e.jsx(se,{...b})]})}const pe=()=>{const{addToast:t}=O(),[n,a]=d.useState([]),[o,h]=d.useState(!0),[x,m]=d.useState({}),[l,u]=d.useState(!1);d.useEffect(()=>{(async()=>{h(!0);try{const[c,j]=await Promise.all([y.listKeys(),y.getStats()]);a(c),m(j)}catch(c){k.error("Error loading developer dashboard data",{error:c instanceof Error?c.message:String(c),stack:c instanceof Error?c.stack:void 0})}finally{h(!1)}})()},[]);const b=async s=>{try{const c=await y.createKey(s);a([c,...n]),t("API Key created successfully","success")}catch{t("Failed to create API key","error")}},w=async s=>{if(confirm("Are you sure you want to revoke this key?")){await y.revokeKey(s);const c=await y.listKeys();a(c),t("API Key revoked","info")}},i=async s=>{confirm("Are you sure you want to delete this key permanently?")&&(await y.deleteKey(s),a(n.filter(c=>c.id!==s)),t("API Key deleted","info"))};return o?e.jsx("div",{className:"flex justify-center py-24",children:e.jsx(R,{className:"w-10 h-10 text-kodo-steel animate-spin"})}):e.jsxs("div",{className:"space-y-8 animate-fadeIn pb-20",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-end gap-4 border-b border-kodo-steel/50 pb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-display font-bold text-white mb-2",children:"DEVELOPER PORTAL"}),e.jsx("p",{className:"text-kodo-content-dim font-mono text-sm",children:"Build on top of the Veza Platform."})]}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(g,{variant:"secondary",icon:e.jsx(W,{className:"w-4 h-4"}),onClick:()=>window.open("https://docs.veza.io","_blank"),children:"Documentation"}),e.jsx(g,{variant:"primary",icon:e.jsx(X,{className:"w-4 h-4"}),onClick:()=>u(!0),children:"Create API Key"})]})]}),e.jsxs(ee,{defaultValue:"overview",className:"w-full",children:[e.jsxs(te,{className:"grid w-full grid-cols-2 mb-8",children:[e.jsxs(U,{value:"overview",className:"flex items-center gap-2",children:[e.jsx(K,{className:"w-4 h-4"}),"Overview & Keys"]}),e.jsxs(U,{value:"docs",className:"flex items-center gap-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"API Documentation"]})]}),e.jsxs(D,{value:"overview",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-8",children:[e.jsx(_,{label:"API Requests (24h)",value:x.requests_24h?.toLocaleString()||0,icon:e.jsx(K,{className:"w-5 h-5"}),trend:5.2,color:"cyan"}),e.jsx(_,{label:"Avg Latency",value:`${x.avg_latency||0}ms`,icon:e.jsx(q,{className:"w-5 h-5"}),trend:-12,color:"lime"}),e.jsx(_,{label:"Active Keys",value:n.length,icon:e.jsx(E,{className:"w-5 h-5"}),color:"gold"})]}),e.jsxs(P,{variant:"default",children:[e.jsx("h3",{className:"font-bold text-white mb-6",children:"Active API Keys"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-xs text-kodo-content-dim uppercase border-b border-kodo-steel/50",children:[e.jsx("th",{className:"pb-3 pl-4",children:"Name"}),e.jsx("th",{className:"pb-3",children:"Key Prefix"}),e.jsx("th",{className:"pb-3",children:"Created"}),e.jsx("th",{className:"pb-3",children:"Last Used"}),e.jsx("th",{className:"pb-3 text-right pr-4",children:"Actions"})]})}),e.jsxs("tbody",{className:"text-sm",children:[n.map(s=>e.jsxs("tr",{className:"border-b border-kodo-steel/20 hover:bg-white/5 transition-colors",children:[e.jsx("td",{className:"py-4 pl-4 font-bold text-white",children:s.name}),e.jsx("td",{className:"py-4 font-mono text-kodo-gold",children:s.prefix}),e.jsx("td",{className:"py-4 text-kodo-content-dim",children:s.created}),e.jsx("td",{className:"py-4 text-kodo-text-main",children:s.lastUsed}),e.jsxs("td",{className:"py-4 text-right pr-4 flex justify-end gap-2",children:[e.jsx(g,{variant:"ghost",size:"icon",className:"h-8 w-8 text-kodo-content-dim hover:text-white",onClick:()=>t("Full key hidden for security"),title:"View Key",children:e.jsx(Q,{className:"w-4 h-4"})}),s.status==="active"?e.jsx(g,{variant:"ghost",size:"icon",className:"h-8 w-8 text-kodo-red hover:bg-kodo-red/10",onClick:()=>w(s.id),title:"Revoke Key",children:e.jsx(A,{className:"w-4 h-4"})}):e.jsx(g,{variant:"ghost",size:"icon",className:"h-8 w-8 text-kodo-content-dim hover:text-white hover:bg-white/10",onClick:()=>i(s.id),title:"Delete Permanently",children:e.jsx(A,{className:"w-4 h-4"})})]})]},s.id)),n.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"py-8 text-center text-kodo-content-dim",children:"No active API keys. Create one to get started."})})]})]})})]})]}),e.jsx(D,{value:"docs",children:e.jsx(P,{variant:"default",className:"p-0 overflow-hidden bg-black/80",children:e.jsx(re,{useIframe:!1})})})]}),l&&e.jsx(oe,{onClose:()=>u(!1),onCreate:b})]})};export{pe as DeveloperDashboardView};