(()=>{const s=window.React;if(!s)return;const e=s.createElement,f=s.useState,k=s.useEffect,a={bg:"var(--app-bg,#0e0e10)",surface:"var(--app-surface,#1a1a1c)",elevated:"var(--app-elevated,#2a2a2e)",rule:"var(--app-rule,rgba(255,255,255,.07))",ink:"var(--app-ink,#e6e3da)",inkSoft:"var(--app-ink-soft,rgba(230,227,218,.62))",inkFaint:"var(--app-ink-faint,rgba(230,227,218,.38))",accent:"var(--app-accent,#00f3ff)",accentDim:"var(--app-accent-dim,rgba(0,243,255,.16))",success:"var(--app-success,#00d4b8)",warn:"var(--app-warn,#f8d974)",fail:"var(--app-fail,#f43f6c)",mono:'var(--app-font-mono,"JetBrains Mono",SFMono-Regular,monospace)'},p={tier:"aaas-x5",hasApiSubscription:!0,month:{includedCap:15e3,includedUsed:4200,includedRemaining:10800,purchasedRemaining:2e3,debt:0,projectedExhaustion:null},window:{cap:1500,used:null,note:"Live 5-hour window is enforced by the proxy; this is the published cap."},week:{cap:5e3,used:1800},keys:[{keyLabel:"aaas_sk_f\u2026ab12",credits:3100,inTok:42e4,cachedTok:12e5,outTok:38e3,lastUsed:"2026-07-06"}]},g=new Intl.NumberFormat("en-IE"),r=i=>g.format(Math.round(i??0)),u=(i,t)=>t>0?Math.min(100,Math.round(i/t*100)):0;function m(i,t,d){const n=u(i,t);return e("span",{style:{display:"block",height:8,borderRadius:4,background:a.accentDim,overflow:"hidden",marginTop:6}},e("span",{style:{display:"block",width:n+"%",height:"100%",background:d?a.fail:a.accent}}))}function l(i,t,d){return e("div",{style:{background:a.surface,border:"1px solid "+a.rule,borderRadius:12,padding:"1rem"}},[e("p",{key:"l",style:{fontFamily:a.mono,fontSize:"0.62rem",textTransform:"uppercase",letterSpacing:"0.12em",color:a.inkFaint,margin:0}},i),e("p",{key:"v",style:{fontSize:"1.5rem",fontWeight:700,color:a.ink,margin:"0.35rem 0 0"}},t),d||null])}function w({pct:i}){if(i<80)return null;const t=i>=95;return e("div",{role:"status",style:{padding:"0.7rem 1rem",borderRadius:8,marginBottom:"1rem",fontFamily:a.mono,fontSize:"0.78rem",color:t?a.fail:a.ink,background:t?"var(--app-fail-dim,rgba(244,63,108,.12))":"var(--app-warn-dim,rgba(248,217,116,.10))",border:"1px solid "+(t?a.fail:a.warn)}},t?"You've used "+i+"% of this month's included API Credits \u2014 top up to avoid interruptions.":"Heads up: "+i+"% of this month's included API Credits used.")}function c(){const i=()=>window.KIND_REGISTRY&&window.KIND_REGISTRY.apiUsage&&window.KIND_REGISTRY.apiUsage.data||p,[t,d]=f(i);if(k(()=>{const o=()=>d(i());return window.addEventListener("api-usage-live-hydrated",o),()=>window.removeEventListener("api-usage-live-hydrated",o)},[]),!t||!t.hasApiSubscription)return e("div",{className:"apiusage",style:{color:a.ink,fontFamily:"var(--app-font,system-ui)",padding:"1.5rem"}},[e("h2",{key:"t",style:{fontSize:"1.1rem",margin:0}},"API Credits"),e("p",{key:"e",style:{color:a.inkSoft,fontSize:"0.9rem"}},"No active GLM API subscription. Choose a plan to get an API key and a live usage dashboard here.")]);const n=t.month,y=u(n.includedUsed,n.includedCap);return e("div",{className:"apiusage",style:{color:a.ink,fontFamily:"var(--app-font,system-ui)",padding:"1.5rem"}},[e("h2",{key:"title",style:{fontSize:"1.1rem",margin:"0 0 0.15rem"}},"API Credits \u2014 "+t.tier),e("p",{key:"sub",style:{color:a.inkFaint,fontSize:"0.72rem",margin:"0 0 1rem"}},"Metered GLM usage. 1 credit = \u20AC0.01. Separate from your canvas Credits."),e(w,{key:"alert",pct:y}),e("div",{key:"grid",style:{display:"grid",gap:"1rem",gridTemplateColumns:"1fr 1fr"}},[l("Monthly included",r(n.includedUsed)+" / "+r(n.includedCap),e("div",{key:"x"},[m(n.includedUsed,n.includedCap,y>=95),e("p",{key:"c",style:{fontSize:"0.8rem",color:a.inkSoft,marginTop:8}},r(n.includedRemaining)+" credits remaining"+(n.projectedExhaustion?" \xB7 projected exhaustion "+new Date(n.projectedExhaustion).toLocaleDateString():""))])),l("Purchased balance",r(n.purchasedRemaining),e("div",{key:"d"},[e("p",{key:"c",style:{fontSize:"0.8rem",color:a.inkSoft,marginTop:8}},"Top-up credits \xB7 never expire"),n.debt>0?e("p",{key:"debt",style:{fontSize:"0.8rem",color:a.fail,marginTop:6}},r(n.debt)+" credits of debt \u2014 settle with a top-up to resume."):null])),l("5-hour window cap",r(t.window.cap),e("p",{key:"n",style:{fontSize:"0.72rem",color:a.inkFaint,marginTop:8}},t.window.note)),l("This week",r(t.week.used??0)+" / "+r(t.week.cap),m(t.week.used??0,t.week.cap,!1))]),e("h3",{key:"kh",style:{fontSize:"0.95rem",margin:"1.5rem 0 0.5rem"}},"Per-key usage (this month)"),t.keys.length===0?e("p",{key:"ke",style:{color:a.inkSoft,fontSize:"0.85rem"}},"No API usage yet this month."):e("table",{key:"kt",style:{width:"100%",borderCollapse:"collapse",fontSize:"0.85rem"}},[e("thead",{key:"th"},e("tr",{style:{textAlign:"left",color:a.inkFaint,fontFamily:a.mono}},["Key","Credits","Input","Cached","Output","Last used"].map(o=>e("th",{key:o,style:{padding:"0.4rem 0"}},o)))),e("tbody",{key:"tb"},t.keys.map(o=>e("tr",{key:o.keyLabel,style:{borderTop:"1px solid "+a.rule}},[e("td",{key:"kl",style:{padding:"0.4rem 0",fontFamily:a.mono}},[o.keyLabel," ",typeof window.ScopeBadge=="function"?e(window.ScopeBadge,{key:"scope",item:o,kind:window.KIND_REGISTRY&&window.KIND_REGISTRY.apiUsage}):null]),e("td",{key:"cr"},r(o.credits)),e("td",{key:"in"},r(o.inTok)),e("td",{key:"ca"},r(o.cachedTok)),e("td",{key:"ou"},r(o.outTok)),e("td",{key:"lu"},o.lastUsed||"\u2014")])))])])}c.displayName="ApiUsageView",window.API_USAGE_VIEW_FN=c,window.VIEWS=window.VIEWS||{},window.VIEWS.apiUsage=c,window.KIND_REGISTRY=window.KIND_REGISTRY||{},window.KIND_REGISTRY.apiUsage=window.KIND_REGISTRY.apiUsage||{id:"apiUsage",label:"API usage",defaultView:"apiUsage",defaultDetail:"none",data:p},window.API_USAGE_SEED=p})();
