1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="3ade9d43-f33a-4362-94dd-aeb3655a93ed",e._sentryDebugIdIdentifier="sentry-dbid-3ade9d43-f33a-4362-94dd-aeb3655a93ed")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1760],{85425:(e,t,s)=>{s.d(t,{$n:()=>a.$,Zp:()=>r.Zp,y$:()=>l.y});var a=s(38007),r=s(87141),l=s(87626)},91760:(e,t,s)=>{s.r(t),s.d(t,{default:()=>o});var a=s(63986),r=s(85425),l=s(31075),d=s(28998),i=s(16346),n=s(15226),c=s(866);function o(){var e;let t=(0,l.useRouter)(),{user:s,isAuthenticated:o}=(0,c.nc)(),[x,h]=(0,i.useState)(!0),[m,g]=(0,i.useState)(null),[u,b]=(0,i.useState)("7d"),[p,y]=(0,i.useState)(null),j=(0,d.Ym)(),f=(null==s||null==(e=s.email)?void 0:e.endsWith("@247sales.com"))||!1;(0,i.useEffect)(()=>o?f?void k():void t.push("/dashboard"):void t.push("/login?redirect=/admin/costs"),[o,f,u,t]);let k=async()=>{h(!0),y(null);try{let e=(await n.FH.get("/api/v1/admin/costs?range=".concat(u))).data;e.success&&g(e.data)}catch(e){y(e.message||"Failed to load cost metrics"),g(w())}finally{h(!1)}},w=()=>{let e=parseInt(u)||7,t=[];for(let s=e-1;s>=0;s--){let e=new Date;e.setDate(e.getDate()-s),t.push({date:e.toISOString().split("T")[0],aiCalls:Math.floor(500*Math.random())+200,tokensUsed:Math.floor(1e5*Math.random())+5e4,estimatedCost:5*Math.random()+2})}return{daily:t,totals:{totalAiCalls:t.reduce((e,t)=>e+t.aiCalls,0),totalTokens:t.reduce((e,t)=>e+t.tokensUsed,0),totalCost:t.reduce((e,t)=>e+t.estimatedCost,0),avgCostPerCall:.008},byTier:[{tier:"FREE",users:1250,aiCalls:2500,cost:5,avgPerUser:.004},{tier:"STARTER",users:320,aiCalls:8500,cost:17,avgPerUser:.053},{tier:"GROWTH",users:145,aiCalls:15200,cost:30.4,avgPerUser:.21},{tier:"PRO",users:68,aiCalls:22e3,cost:44,avgPerUser:.65},{tier:"ENTERPRISE",users:12,aiCalls:18e3,cost:36,avgPerUser:3}],byFeature:[{feature:"Message Generation",calls:25e3,tokens:25e5,cost:50,percentOfTotal:38},{feature:"Content Scoring",calls:18e3,tokens:9e5,cost:18,percentOfTotal:14},{feature:"Debug Diagnosis",calls:5e3,tokens:75e4,cost:22.5,percentOfTotal:17},{feature:"Improvements",calls:12e3,tokens:12e5,cost:24,percentOfTotal:18},{feature:"Intent Classification",calls:8e3,tokens:24e4,cost:4.8,percentOfTotal:4},{feature:"Feedback Analysis",calls:3e3,tokens:18e4,cost:3.6,percentOfTotal:3},{feature:"Other",calls:4200,tokens:42e4,cost:8.4,percentOfTotal:6}],projections:{mtdCost:892.5,projectedMonthEnd:1450,budget:1500,variance:-50}}},v=e=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(e),N=e=>new Intl.NumberFormat("en-US").format(e);return o&&f?(0,a.jsxs)("div",{className:"max-w-7xl mx-auto py-8 px-4",children:[(0,a.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"Cost Dashboard"}),(0,a.jsx)("p",{className:"text-gray-600 dark:text-white/60",children:"Monitor AI usage and costs across all features"})]}),(0,a.jsxs)("div",{className:"flex gap-2",children:[(0,a.jsxs)("select",{value:u,onChange:e=>b(e.target.value),className:"px-3 py-2 border border-gray-300 dark:border-white/20 rounded-lg text-sm bg-white dark:bg-brand-bg-secondary dark:text-white",children:[(0,a.jsx)("option",{value:"7d",children:"Last 7 days"}),(0,a.jsx)("option",{value:"14d",children:"Last 14 days"}),(0,a.jsx)("option",{value:"30d",children:"Last 30 days"}),(0,a.jsx)("option",{value:"90d",children:"Last 90 days"})]}),(0,a.jsx)(r.$n,{variant:"outline",onClick:k,children:"Refresh"})]})]}),p&&(0,a.jsxs)("div",{className:"mb-4 p-4 bg-status-warning-50 dark:bg-status-warning-900/20 border border-status-warning-200 dark:border-status-warning/30 rounded-lg text-status-warning-700 dark:text-status-warning-300",children:[p," - Showing demo data"]}),x?(0,a.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,a.jsx)(r.y$,{size:40})}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-8",children:[(0,a.jsxs)(r.Zp,{className:"p-5 dark:bg-brand-bg-secondary dark:border-white/10",children:[(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-white/70 mb-1",children:"Total AI Calls"}),(0,a.jsx)("p",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:N((null==m?void 0:m.totals.totalAiCalls)||0)})]}),(0,a.jsxs)(r.Zp,{className:"p-5 dark:bg-brand-bg-secondary dark:border-white/10",children:[(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-white/70 mb-1",children:"Total Tokens"}),(0,a.jsx)("p",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:N((null==m?void 0:m.totals.totalTokens)||0)})]}),(0,a.jsxs)(r.Zp,{className:"p-5 dark:bg-brand-bg-secondary dark:border-white/10",children:[(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-white/70 mb-1",children:"Total Cost"}),(0,a.jsx)("p",{className:"text-2xl font-bold text-cyan-500",children:v((null==m?void 0:m.totals.totalCost)||0)})]}),(0,a.jsxs)(r.Zp,{className:"p-5 dark:bg-brand-bg-secondary dark:border-white/10",children:[(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-white/70 mb-1",children:"Avg Cost/Call"}),(0,a.jsx)("p",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:v((null==m?void 0:m.totals.avgCostPerCall)||0)})]})]}),(0,a.jsxs)(r.Zp,{className:"p-6 mb-8 dark:bg-brand-bg-secondary dark:border-white/10",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Monthly Projections"}),(0,a.jsxs)("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-6",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-white/70",children:"MTD Cost"}),(0,a.jsx)("p",{className:"text-xl font-bold text-gray-900 dark:text-white",children:v((null==m?void 0:m.projections.mtdCost)||0)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-white/70",children:"Projected Month End"}),(0,a.jsx)("p",{className:"text-xl font-bold text-gray-900 dark:text-white",children:v((null==m?void 0:m.projections.projectedMonthEnd)||0)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-white/70",children:"Monthly Budget"}),(0,a.jsx)("p",{className:"text-xl font-bold text-gray-900 dark:text-white",children:v((null==m?void 0:m.projections.budget)||0)})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{className:"text-sm text-gray-500 dark:text-white/70",children:"Variance"}),(0,a.jsx)("p",{className:"text-xl font-bold ".concat(((null==m?void 0:m.projections.variance)||
10)>=0?"text-status-success-600":"text-status-error-600"),children:v((null==m?void 0:m.projections.variance)||0)})]})]}),(0,a.jsxs)("div",{className:"mt-6",children:[(0,a.jsxs)("div",{className:"flex justify-between text-sm mb-2",children:[(0,a.jsx)("span",{className:"text-gray-600 dark:text-white/60",children:"Budget usage"}),(0,a.jsxs)("span",{className:"font-medium dark:text-white",children:[(((null==m?void 0:m.projections.mtdCost)||0)/((null==m?void 0:m.projections.budget)||1)*100).toFixed(1),"%"]})]}),(0,a.jsx)("div",{className:"w-full bg-gray-200 dark:bg-white/10 rounded-full h-3",children:(0,a.jsx)("div",{className:"h-3 rounded-full ".concat(((null==m?void 0:m.projections.mtdCost)||0)/((null==m?void 0:m.projections.budget)||1)*100>90?"bg-status-error":((null==m?void 0:m.projections.mtdCost)||0)/((null==m?void 0:m.projections.budget)||1)*100>70?"bg-status-warning":"bg-cyan-500"),style:{width:"".concat(Math.min(((null==m?void 0:m.projections.mtdCost)||0)/((null==m?void 0:m.projections.budget)||1)*100,100),"%")}})})]})]}),(0,a.jsxs)(r.Zp,{className:"p-6 mb-8 dark:bg-brand-bg-secondary dark:border-white/10",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Daily Costs"}),(0,a.jsx)("div",{className:"h-64 flex items-end gap-1",children:null==m?void 0:m.daily.map(e=>{let t=Math.max(...(null==m?void 0:m.daily.map(e=>e.estimatedCost))||[1]),s=e.estimatedCost/t*100;return(0,a.jsxs)("div",{className:"flex-1 flex flex-col items-center",title:"".concat(e.date,": ").concat(v(e.estimatedCost)),children:[(0,a.jsx)("div",{className:"w-full bg-cyan-500 rounded-t hover:bg-cyan-600 transition-colors",style:{height:"".concat(s,"%"),minHeight:"4px"}}),(0,a.jsx)("span",{className:"text-xs text-gray-500 dark:text-white/70 mt-1 transform -rotate-45 origin-top-left",children:new Date(e.date).toLocaleDateString(j,{month:"short",day:"numeric"})})]},e.date)})})]}),(0,a.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[(0,a.jsxs)(r.Zp,{className:"p-6 mb-8 dark:bg-brand-bg-secondary dark:border-white/10",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Cost by Tier"}),(0,a.jsx)("div",{className:"overflow-x-auto",children:(0,a.jsxs)("table",{className:"w-full",children:[(0,a.jsx)("thead",{children:(0,a.jsxs)("tr",{className:"border-b dark:border-white/10",children:[(0,a.jsx)("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-500 dark:text-white/70",children:"Tier"}),(0,a.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-white/70",children:"Users"}),(0,a.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-white/70",children:"AI Calls"}),(0,a.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-white/70",children:"Cost"}),(0,a.jsx)("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-500 dark:text-white/70",children:"Avg/User"})]})}),(0,a.jsx)("tbody",{children:null==m?void 0:m.byTier.map(e=>(0,a.jsxs)("tr",{className:"border-b dark:border-white/10 hover:bg-gray-50 dark:hover:bg-white/5",children:[(0,a.jsx)("td",{className:"py-3 px-4",children:(0,a.jsx)("span",{className:"px-2 py-1 rounded-full text-xs font-medium ".concat("FREE"===e.tier?"bg-gray-100 dark:bg-gray-500/20 text-gray-700 dark:text-gray-300":"STARTER"===e.tier?"bg-status-info-100 dark:bg-status-info/20 text-status-info-700 dark:text-status-info-300":"GROWTH"===e.tier?"bg-status-success-100 dark:bg-status-success/20 text-status-success-700 dark:text-status-success-300":"PRO"===e.tier?"bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-300":"bg-status-warning-100 dark:bg-status-warning/20 text-status-warning-700 dark:text-status-warning-300"),children:e.tier})}),(0,a.jsx)("td",{className:"py-3 px-4 text-right text-gray-900 dark:text-white",children:N(e.users)}),(0,a.jsx)("td",{className:"py-3 px-4 text-right text-gray-900 dark:text-white",children:N(e.aiCalls)}),(0,a.jsx)("td",{className:"py-3 px-4 text-right font-medium text-gray-900 dark:text-white",children:v(e.cost)}),(0,a.jsx)("td",{className:"py-3 px-4 text-right text-gray-600 dark:text-white/60",children:v(e.avgPerUser)})]},e.tier))})]})})]}),(0,a.jsxs)(r.Zp,{className:"p-6 dark:bg-brand-bg-secondary dark:border-white/10",children:[(0,a.jsx)("h2",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Cost by Feature"}),(0,a.jsx)("div",{className:"space-y-4",children:null==m?void 0:m.byFeature.map(e=>(0,a.jsxs)("div",{children:[(0,a.jsxs)("div",{className:"flex justify-between items-center mb-1",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-gray-900 dark:text-white",children:e.feature}),(0,a.jsxs)("div",{className:"text-right",children:[(0,a.jsx)("span",{className:"text-sm font-medium text-gray-900 dark:text-white",children:v(e.cost)}),(0,a.jsxs)("span",{className:"text-xs text-gray-500 dark:text-white/70 ml-2",children:["(",e.percentOfTotal,"%)"]})]})]}),(0,a.jsx)("div",{className:"w-full bg-gray-200 dark:bg-white/10 rounded-full h-2",children:(0,a.jsx)("div",{className:"h-2 rounded-full bg-cyan-500",style:{width:"".concat(e.percentOfTotal,"%")}})}),(0,a.jsxs)("div",{className:"flex justify-between text-xs text-gray-500 dark:text-white/70 mt-1",children:[(0,a.jsxs)("span",{children:[N(e.calls)," calls"]}),(0,a.jsxs)("span",{children:[N(e.tokens)," tokens"]})]})]},e.feature))})]})]})]})]}):(0,a.jsx)("div",{className:"flex items-center justify-center min-h-[60vh]",children:(0,a.jsx)(r.y$,{size:40})})}}}]);
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.