1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="f60d5af7-ea47-4ab4-8dbd-dca442ec12e7",e._sentryDebugIdIdentifier="sentry-dbid-f60d5af7-ea47-4ab4-8dbd-dca442ec12e7")}catch(e){}}(),(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6814],{25521:(e,t,r)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/costs",function(){return r(72794)}])},72794:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>y});var s=r(78488),a=r(81204),d=r(72094),l=r(48227),i=r(58440),n=r(74221),o=r(59782);function c(e){let{title:t,value:r,subtitle:a,trend:d,color:l="primary"}=e;return(0,s.jsx)("div",{className:"bg-white dark:bg-gray-800 rounded-xl p-6 shadow-sm border border-gray-100 dark:border-gray-700",children:(0,s.jsxs)("div",{className:"flex items-start justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-1",children:t}),(0,s.jsx)("p",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:r}),a&&(0,s.jsx)("p",{className:"text-xs text-gray-400 dark:text-gray-500 mt-1",children:a})]}),(0,s.jsxs)("div",{className:"w-10 h-10 rounded-lg bg-gradient-to-br ".concat({primary:"from-blue-500 to-blue-600",success:"from-green-500 to-green-600",warning:"from-yellow-500 to-yellow-600",danger:"from-red-500 to-red-600"}[l]," flex items-center justify-center"),children:["success"===l&&(0,s.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),"warning"===l&&(0,s.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"danger"===l&&(0,s.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}),"primary"===l&&(0,s.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})})]})]})})}function x(e){let{label:t,spent:r,limit:a,percent:d}=e;return(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsxs)("div",{className:"flex justify-between text-sm mb-1",children:[(0,s.jsx)("span",{className:"text-gray-600 dark:text-gray-400",children:t}),(0,s.jsxs)("span",{className:"font-medium text-gray-900 dark:text-white",children:["$",r.toFixed(2)," / $",a.toFixed(2)]})]}),(0,s.jsx)("div",{className:"h-3 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:(0,s.jsx)("div",{className:"h-full ".concat(d>=100?"bg-red-500":d>=80?"bg-yellow-500":"bg-green-500"," transition-all duration-500"),style:{width:"".concat(Math.min(d,100),"%")}})}),(0,s.jsxs)("p",{className:"text-xs text-gray-500 dark:text-gray-400 mt-1",children:[d.toFixed(1),"% used ⢠$",(a-r).toFixed(2)," remaining"]})]})}function m(e){let{data:t}=e,r=Object.entries(t).sort((e,t)=>t[1].cost-e[1].cost);return 0===r.length?(0,s.jsx)("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"No data yet. Costs will appear here after Gemini API calls are made."}):(0,s.jsx)("div",{className:"overflow-x-auto",children:(0,s.jsxs)("table",{className:"w-full",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[(0,s.jsx)("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:"Model"}),(0,s.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:"Calls"}),(0,s.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:"Images"}),(0,s.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:"Cost"})]})}),(0,s.jsx)("tbody",{children:r.map(e=>{let[t,r]=e;return(0,s.jsxs)("tr",{className:"border-b border-gray-100 dark:border-gray-700/50 hover:bg-gray-50 dark:hover:bg-gray-700/30",children:[(0,s.jsx)("td",{className:"py-3 px-4",children:(0,s.jsx)("span",{className:"text-sm font-medium text-gray-900 dark:text-white",children:t.replace("models/","")})}),(0,s.jsx)("td",{className:"py-3 px-4 text-right text-sm text-gray-600 dark:text-gray-300",children:r.calls.toLocaleStr
1ing()}),(0,s.jsx)("td",{className:"py-3 px-4 text-right text-sm text-gray-600 dark:text-gray-300",children:r.images.toLocaleString()}),(0,s.jsxs)("td",{className:"py-3 px-4 text-right text-sm font-medium text-gray-900 dark:text-white",children:["$",r.cost.toFixed(4)]})]},t)})})]})})}function g(e){let{users:t}=e;return 0===t.length?(0,s.jsx)("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"No user data yet."}):(0,s.jsx)("div",{className:"overflow-x-auto",children:(0,s.jsxs)("table",{className:"w-full",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"border-b border-gray-200 dark:border-gray-700",children:[(0,s.jsx)("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:"User ID"}),(0,s.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:"Calls"}),(0,s.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:"Images"}),(0,s.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-gray-400",children:"Cost"})]})}),(0,s.jsx)("tbody",{children:t.map((e,t)=>(0,s.jsxs)("tr",{className:"border-b border-gray-100 dark:border-gray-700/50 hover:bg-gray-50 dark:hover:bg-gray-700/30",children:[(0,s.jsx)("td",{className:"py-3 px-4",children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"w-6 h-6 rounded-full bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center text-xs text-white font-medium",children:t+1}),(0,s.jsxs)("span",{className:"text-sm font-mono text-gray-600 dark:text-gray-300",children:[e.user_id.slice(0,8),"..."]})]})}),(0,s.jsx)("td",{className:"py-3 px-4 text-right text-sm text-gray-600 dark:text-gray-300",children:e.calls.toLocaleString()}),(0,s.jsx)("td",{className:"py-3 px-4 text-right text-sm text-gray-600 dark:text-gray-300",children:e.images.toLocaleString()}),(0,s.jsxs)("td",{className:"py-3 px-4 text-right text-sm font-medium text-gray-900 dark:text-white",children:["$",e.cost_usd.toFixed(4)]})]},e.user_id))})]})})}function h(e){let{data:t}=e;if(0===t.length)return(0,s.jsx)("div",{className:"text-center py-8 text-gray-500 dark:text-gray-400",children:"No daily data yet."});let r=Math.max(...t.map(e=>e.cost_usd),1);return(0,s.jsx)("div",{className:"space-y-2",children:t.slice(0,7).map(e=>(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 w-20",children:new Date(e.date).toLocaleDateString("en-US",{weekday:"short",month:"short",day:"numeric"})}),(0,s.jsx)("div",{className:"flex-1 h-6 bg-gray-100 dark:bg-gray-700 rounded overflow-hidden",children:(0,s.jsx)("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-600 flex items-center justify-end pr-2",style:{width:"".concat(e.cost_usd/r*100,"%")},children:e.cost_usd>0&&(0,s.jsxs)("span",{className:"text-xs text-white font-medium",children:["$",e.cost_usd.toFixed(2)]})})}),(0,s.jsxs)("span",{className:"text-xs text-gray-500 dark:text-gray-400 w-16 text-right",children:[e.images," imgs"]})]},e.date))})}function y(){let e=(0,d.useRouter)(),{addToast:t}=(0,o.W)(),{isAuthenticated:r,_hasHydrated:y}=(0,l.useUserStore)(),[u,b]=(0,a.useState)(!0),[p,j]=(0,a.useState)(null),[k,f]=(0,a.useState)(null),[N,v]=(0,a.useState)([]),[w,_]=(0,a.useState)([]),[E,D]=(0,a.useState)(null),[L,C]=(0,a.useState)(!1),S=(0,a.useCallback)(async()=>{try{let[e,t,r,s,a]=await Promise.all([n.Ay.get("/admin/costs/budget"),n.Ay.get("/admin/costs/summary?days=7"),n.Ay.get("/admin/costs/users?limit=10"),n.Ay.get("/admin/costs/daily?days=7"),n.Ay.get("/admin/health")]);j(e.data),f(t.data),v(r.data),_(s.data.daily||[]),D(a.data)}catch(s){var r;console.error("Failed to load cost data:",s),(null==s||null==(r=s.response)?void 0:r.status)===403?(t("error","Admin access required"),e.push("/")):t("error","Failed to load cost data")}finally{b(!1)}},[t,e]);return((0,a.useEffect)(()=>{if(y){if(!r)return void e.push("/auth");S()}},[y,r,S,e]),(0,a.useEffect)(()=>
1{if(!L)return;let e=setInterval(S,3e4);return()=>clearInterval(e)},[L,S]),!y||u)?(0,s.jsxs)("div",{className:"min-h-screen bg-gray-50 dark:bg-gray-900",children:[(0,s.jsx)(i.A,{}),(0,s.jsx)("div",{className:"container mx-auto px-4 py-12",children:(0,s.jsxs)("div",{className:"text-center",children:[(0,s.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500 mx-auto"}),(0,s.jsx)("p",{className:"mt-4 text-gray-600 dark:text-gray-400",children:"Loading cost data..."})]})})]}):(0,s.jsxs)("div",{className:"min-h-screen bg-gray-50 dark:bg-gray-900",children:[(0,s.jsx)(i.A,{}),(0,s.jsxs)("div",{className:"container mx-auto px-4 py-8",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-8",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{className:"text-3xl font-bold text-gray-900 dark:text-white mb-1",children:"Gemini API Cost Dashboard"}),(0,s.jsx)("p",{className:"text-gray-600 dark:text-gray-400",children:"Real-time cost monitoring and budget tracking"})]}),(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)("label",{className:"flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400",children:[(0,s.jsx)("input",{type:"checkbox",checked:L,onChange:e=>C(e.target.checked),className:"rounded border-gray-300 text-blue-500 focus:ring-blue-500"}),"Auto-refresh (30s)"]}),(0,s.jsxs)("button",{onClick:S,className:"px-4 py-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg transition-colors flex items-center gap-2",children:[(0,s.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),"Refresh"]})]})]}),E&&"OK"!==E.budget_status&&(0,s.jsx)("div",{className:"mb-6 p-4 rounded-lg ".concat("BUDGET_EXCEEDED"===E.budget_status?"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800":"bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800"),children:(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("svg",{className:"w-5 h-5 ".concat("BUDGET_EXCEEDED"===E.budget_status?"text-red-500":"text-yellow-500"),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,s.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"font-medium ".concat("BUDGET_EXCEEDED"===E.budget_status?"text-red-800 dark:text-red-200":"text-yellow-800 dark:text-yellow-200"),children:"BUDGET_EXCEEDED"===E.budget_status?"Budget Exceeded!":"Budget Warning"}),(0,s.jsx)("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"BUDGET_EXCEEDED"===E.budget_status?"Daily or monthly budget has been exceeded. New generations may be blocked.":"Approaching budget limit. Monitor closely."})]})]})}),(0,s.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8",children:[(0,s.jsx)(c,{title:"Today's Spend",value:"$".concat(((null==p?void 0:p.daily.spent_usd)||0).toFixed(2)),subtitle:"Limit: $".concat((null==p?void 0:p.daily.limit_usd)||50),color:(e=>{switch(e){case"OK":return"success";case"BUDGET_WARNING":return"warning";case"BUDGET_EXCEEDED":return"danger";default:return"primary"}})((null==E?void 0:E.budget_status)||"OK")}),(0,s.jsx)(c,{title:"Monthly Spend",value:"$".concat(((null==p?void 0:p.monthly.spent_usd)||0).toFixed(2)),subtitle:"Limit: $".concat((null==p?void 0:p.monthly.limit_usd)||500),color:"primary"}),(0,s.jsx)(c,{title:"Total Images (7d)",value:((null==k?void 0:k.total_images)||0).toLocaleString(),subtitle:"".concat((null==k?void 0:k.total_calls)||0," API calls"),color:"primary"}),(0,s.jsx)(c,{title:"Avg Cost/Image",value:"$".concat((null==k?void 0:k.total_images)?(k.total_cost_usd/k.total_images).toFixed(4):"0.00"),subtitle:"Last 7 days",color:"primary"})]}),(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl p-6 shadow-sm border border-gray-100 dark:border-gray-700 mb-8",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Budget Progress"}),p&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(x,{label:"Daily Budget",spent:p.daily.spent_usd,limit:p.daily.limit_usd,percent:p.daily.percent_used}),(0,s.jsx)(x,{label:"Monthly Budget",spent:p.monthly.spent_usd,limit:p.monthly.limit_usd,percent:p.monthly.percent_used}),(0,s.jsxs)("div",{className:"mt-4 pt-4 border-t border-gray-100 dark:border-gray-700 flex gap-6 text-sm",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-gray-500 dark:text-gray-400",children:"Per-user daily limit:"})," ",(0,s.jsxs)("span",{className:"font-medium text-gray-900 dark:text-white",children:["$",p.per_user_daily_limit_usd]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-gray-500 dark:text-gray-400",children:"Hard block:"})," ",(0,s.jsx)("span",{className:"font-medium ".concat(p.hard_block_enabled?"text-red-500":"text-gray-900 dark:text-white"),children:p.hard_block_enabled?"Enabled":"Disabled"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("span",{className:"text-gray-500 dark:text-gray-400",children:"Alert threshold:"})," ",(0,s.jsxs)("span",{className:"font-medium text-gray-900 dark:text-white",children:[p.alert_threshold_pct,"%"]})]})]})]})]}),(0,s.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8",children:[(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl p-6 shadow-sm border border-gray-100 dark:border-gray-700",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Cost by Model (7 days)"}),(0,s.jsx)(m,{data:(null==k?void 0:k.by_model)||{}})]}),(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl p-6 shadow-sm border border-gray-100 dark:border-gray-700",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Daily Spend (Last 7 Days)"}),(0,s.jsx)(h,{data:w})]})]}),(0,s.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-xl p-6 shadow-sm border border-gray-100 dark:border-gray-700",children:[(0,s.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Top Users by Spend (30 days)"}),(0,s.jsx)(g,{users:N})]}),(0,s.jsxs)("div",{className:"mt-8 text-center text-sm text-gray-500 dark:text-gray-400",children:[(0,s.jsxs)("p",{children:["Last updated: ",(null==E?void 0:E.timestamp)?new Date(E.timestamp).toLocaleStr
1ing():"N/A"]}),(0,s.jsx)("p",{className:"mt-1",children:"Pricing: gemini-3-pro-image = $0.134/image | gemini-2.5-flash-image = $0.039/image"})]})]})]})}}},e=>{e.O(0,[8310,384,5155,7528,9293,8440,636,6593,8792],()=>e(e.s=25521)),_N_E=e.O()}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.