1import{r as b,a as Fe,u as Pe,b as Ee,b$ as Be,e as L,w as C,j as e,B as Z,C as j,h as p,aE as S,a_ as qe,i as Ke,p as Oe,q as _e,s as I,b2 as G,a7 as N,a8 as v,ac as k,aL as R,N as F,t as P,a3 as ze,az as He,aZ as Ie,O as Ge,v as Ve,V as We,f as Ye}from"./index-b7ahOnPe.js";import{S as Xe,a as Qe,b as Ze,c as Je,d as es}from"./select-CDAcrVjZ.js";import{S as A}from"./skeleton-Cb-VBKAb.js";import{T as J,a as ee,b as T,c as m,d as se,e as l}from"./table-BfOagCCI.js";import{a as ss,s as he}from"./startOfMonth-CEP8CDJi.js";import{D as as}from"./download-DSpx32Dm.js";import{A as ts}from"./arrow-up-Cdf4Zvz4.js";import{R as E,C as ae,X as te,Y as re,T as B,a as ue,B as rs,b as ds}from"./BarChart-H5UicWwF.js";import{A as ge,a as je}from"./AreaChart--HWxUc_T.js";import{P as pe,a as fe}from"./PieChart-HWEWmXzo.js";import{C as ns}from"./chevron-left-BF8gY2dX.js";import{T as is}from"./trending-up-BA6wwyrK.js";import{A as ls}from"./activity-Su9kKUkj.js";import{s as de}from"./subDays-INs-n4Is.js";import"./index-c8fjdzK-.js";import"./addDays-DE5RhVvA.js";function ye(f,V){return ss(f,-V)}const cs=[{value:"7days",label:"Last 7 Days"},{value:"30days",label:"Last 30 Days"},{value:"90days",label:"Last 90 Days"},{value:"thisMonth",label:"This Month"},{value:"lastMonth",label:"Last Month"},{value:"year",label:"This Year"},{value:"all",label:"All Time"}],q=["hsl(221, 83%, 53%)","hsl(160, 84%, 39%)","hsl(38, 92%, 50%)","hsl(271, 81%, 56%)","hsl(330, 81%, 60%)","hsl(199, 89%, 48%)","hsl(32, 95%, 44%)","hsl(239, 84%, 67%)"];function Ss(){const[f,V]=b.useState("30days"),[d,be]=b.useState({}),[Ne,ve]=b.useState("usage"),[K,W]=b.useState(1),ke=10,{user:g,isVerifiedDoctor:U}=Fe(),[,Y]=Pe(),{toast:X}=Ee();b.useEffect(()=>{g?g&&g.role==="doctor"&&!g.verified&&Y("/verification"):Y("/login")},[g,Y]),b.useEffect(()=>{const s=new Date;let a,r=new Date;switch(f){case"7days":a=de(s,7);break;case"30days":a=de(s,30);break;case"90days":a=de(s,90);break;case"thisMonth":a=he(s);break;case"lastMonth":a=he(ye(s,1)),r=Be(ye(s,1));break;case"year":a=new Date(s.getFullYear(),0,1);break;case"all":a=void 0;break}be({startDate:a==null?void 0:a.toISOString(),endDate:r.toISOString()}),W(1)},[f]);const{data:c,isLoading:we,isError:De}=L({queryKey:["/api/tokens/usage",d],queryFn:async()=>{const s=new URLSearchParams;d.startDate&&s.append("startDate",d.startDate),d.endDate&&s.append("endDate",d.endDate),(f==="90days"||f==="year"||f==="all")&&s.append("limit","60");const a=s.toString(),r=await fetch(`/api/tokens/usage${a?`?${a}`:""}`);if(!r.ok)throw new Error("Failed to fetch token usage data");return r.json()},enabled:!!g&&U}),{data:t,isLoading:Ce}=L({queryKey:["/api/tokens"],enabled:!!g&&U}),{data:i,isLoading:ne,isError:Se}=L({queryKey:["/api/tokens/usage-by-category",d],queryFn:async()=>{const s=new URLSearchParams;d.startDate&&s.append("startDate",d.startDate),d.endDate&&s.append("endDate",d.endDate);const a=s.toString(),r=await fetch(`/api/tokens/usage-by-category${a?`?${a}`:""}`);if(!r.ok)throw new Error("Failed to fetch category data");return r.json()},enabled:!!g&&U}),{data:Q,isLoading:Te,isError:Ae}=L({queryKey:["/api/tokens/balance-history",d],queryFn:async()=>{const s=new URLSearchParams;d.startDate&&s.append("startDate",d.startDate),d.endDate&&s.append("endDate",d.endDate);const a=s.toString(),r=await fetch(`/api/tokens/balance-history${a?`?${a}`:""}`);if(!r.ok)throw new Error("Failed to fetch balance history");return r.json()},enabled:!!g&&U}),{data:w,isLoading:Ue,isError:Me}=L({queryKey:["/api/payments/history",d,K],queryFn:async()=>{const s=new URLSearchParams;d.startDate&&s.append("startDate",d.startDate),d.endDate&&s.append("endDate",d.endDate),s.append("page",String(K)),s.append("limit",String(ke));const a=s.toString(),r=await fetch(`/api/payments/history?${a}`);if(!r.ok)throw new Error("Failed to fetch transaction data");const n=await r.json();return Array.isArray(n)?{transactions:n,pagination:{page:1,limit:n.length,total:n.length,totalPages:1}}:n},enabled:!!g&&U}),{data:y,isLoading:$e}=L({queryKey:["/api/doctor/credit-rewards"],queryFn:async()=>{const s=await Ye("GET","/api/doctor/credit-rewards");return s.ok?s.json():{rewards:[]}},enabled:!!g&&U}),O=b.useMemo(()=>
1{if(!t)return[];const s=(t.freeTokens||0)+(t.bonusTokens||0)+(t.purchasedTokens||0);return s===0?[]:[{source:"Subscription Credits",tokens:t.freeTokens||0,percentage:Math.round((t.freeTokens||0)/s*100),color:q[0]},{source:"Bonus & Rewards",tokens:t.bonusTokens||0,percentage:Math.round((t.bonusTokens||0)/s*100),color:q[1]},{source:"Purchased",tokens:t.purchasedTokens||0,percentage:Math.round((t.purchasedTokens||0)/s*100),color:q[2]}].filter(a=>a.tokens>0)},[t]),h=b.useMemo(()=>{if(!c||c.length===0)return{totalTokens:0,averageDaily:0,highestUsage:{date:"",tokens:0},lowestUsage:{date:"",tokens:0}};const s=c.reduce((n,u)=>n+u.tokens,0),a=Math.round(s/c.length*100)/100,r=[...c].sort((n,u)=>u.tokens-n.tokens);return{totalTokens:Math.round(s*100)/100,averageDaily:a,highestUsage:r[0],lowestUsage:r[r.length-1]}},[c]),ie=s=>{switch(s){case"credit_add":return"Profile Completion Reward";case"signup_bonus":return"Signup Bonus";case"referral_bonus":return"Referral Bonus";case"admin_gift":return"Admin Credit";case"admin_addition":return"Admin Credit";case"admin_add":return"Admin Credit";case"weekly_reset":return"Weekly Allocation";case"weekly_allocation":return"Weekly Allocation";case"org_allocation":return"Organization Credit";case"monthly_reset":return"Monthly Allocation";case"subscription_bonus":return"Subscription Bonus";default:return"Credit Addition"}},D=s=>
1{try{return C(new Date(s),"MMM d, yyyy")}catch{return"N/A"}},le=s=>s.planId?"Subscription":s.tokenPlanId?"Credit Purchase":"Payment",ce=s=>s.tokenPlanId?"bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-300":s.planId?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"bg-muted",oe=s=>{switch(s){case"success":return"Completed";case"pending":case"created":return"Pending";case"failed":return"Failed";case"cancelled":return"Cancelled";default:return(s==null?void 0:s.replace(/_/g," ").replace(/\b\w/g,a=>a.toUpperCase()))||"Unknown"}},me=s=>{switch(s){case"success":return"bg-green-50 dark:bg-green-900/20 text-green-700 dark:text-green-300";case"pending":case"created":return"bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300";case"failed":return"bg-red-50 dark:bg-red-900/20 text-red-700 dark:text-red-300";case"cancelled":return"bg-gray-50 dark:bg-gray-900/20 text-gray-600 dark:text-gray-400";default:return"bg-muted"}},xe=s=>{var a;return(a=s.orderDetail)!=null&&a.finalPrice?`â¹${s.orderDetail.finalPrice}`:s.transactionAmount>0?`â¹${s.transactionAmount}`:"Free"},o=s=>s==null?"0":s>=1e3?s.toLocaleString(void 0,{maximumFractionDigits:2}):String(Math.round(s*100)/100),Le=b.useCallback(()=>{try{const s=[["Date","Credits Used"]];c&&c.forEach(x=>s.push([x.date,String(x.tokens)])),i&&i.length>0&&(s.push([]),s.push(["Category","Credits","Percentage","Sessions"]),i.forEach(x=>s.push([x.category,String(x.value),`${x.percentage}%`,String(x.count)]))),y!=null&&y.rewards&&y.rewards.length>0&&(s.push([]),s.push(["Reward Date","Type","Credits","Description"]),y.rewards.forEach(x=>s.push([D(x.createdAt),ie(x.type),String(x.credits),x.description])));const a=s.map(x=>x.map(Re=>`"${Re}"`).join(",")).join(` 2`),r=new Blob([a],{type:"text/csv"}),n=URL.createObjectURL(r),u=document.createElement("a");u.href=n,u.download=`analytics-${f}-${C(new Date,"yyyy-MM-dd")}.csv`,u.click(),URL.revokeObjectURL(n),X({title:"Export complete",description:"Your analytics data has been downloaded as CSV."})}catch{X({title:"Export failed",description:"Could not export analytics data.",variant:"destructive"})}},[c,i,y,f,X]);if(!g||we||Ce)return e.jsxs("div",{className:"container mx-auto py-8 px-4","data-testid":"analytics-loading",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Analytics"}),e.jsx(A,{className:"h-10 w-40"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-8",children:[e.jsx(A,{className:"h-32"}),e.jsx(A,{className:"h-32"}),e.jsx(A,{className:"h-32"})]}),e.jsx(A,{className:"h-80 w-full mb-8"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(A,{className:"h-96"}),e.jsx(A,{className:"h-96"})]})]});const _=({message:s})=>e.jsx("div",{className:"flex items-center justify-center py-12","data-testid":"error-state",children:e.jsxs(Ge,{variant:"destructive",className:"max-w-md",children:[e.jsx(Ve,{className:"h-4 w-4"}),e.jsx(We,{children:s})]})}),M=({message:s,sub:a})=>e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center","data-testid":"empty-state",children:[e.jsx(ls,{className:"h-12 w-12 text-muted-foreground/40 mb-3"}),e.jsx("p",{className:"text-base text-muted-foreground mb-1",children:s}),a&&e.jsx("p",{className:"text-sm text-muted-foreground/70",children:a})]}),$=w==null?void 0:w.pagination,z=(w==null?void 0:w.transactions)||(Array.isArray(w)?w:[]),H=(y==null?void 0:y.rewards)||[];return e.jsxs("div",{className:"container mx-auto py-8 px-4","data-testid":"analytics-page",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row items-start sm:items-center justify-between mb-8 gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold","data-testid":"text-page-title",children:"Usage Analytics"}),e.jsx("p",{className:"text-muted-foreground",children:"Track your credit usage, balance, and transactions"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs(Xe,{value:f,onValueChange:V,children:[e.jsx(Qe,{className:"w-[180px]","data-testid":"select-time-range",children:e.jsx(Ze,{placeholder:"Select time range"})}),e.jsx(Je,{children:cs.map(s=>e.jsx(es,{value:s.value,children:s.label},s.value))})]}),e.jsx(Z,{variant:"outline",size:"icon",className:"h-10 w-10",onClick:Le,title:"Export as CSV","data-testid":"button-export-csv",children:e.jsx(as,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-8",children:[e.jsx(j,{"data-testid":"card-available-credits",children:e.jsxs(p,{className:"pt-6",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Available Credits"}),e.jsx("h3",{className:"text-2xl font-bold mt-1","data-testid":"text-available-credits",children:t?S(t.credits??t.totalAvailable??0):"0"})]}),e.jsx("div",{className:"p-2 bg-green-50 dark:bg-green-900/20 rounded-full",children:e.jsx(qe,{className:"h-5 w-5 text-green-600 dark:text-green-400"})})]}),(t==null?void 0:t.weeklyResetDate)&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2","data-testid":"text-reset-date",children:["Next reset: ",D(t.weeklyResetDate)]})]})}),e.jsx(j,{"data-testid":"card-period-usage",children:e.jsxs(p,{className:"pt-6",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Period Usage"}),e.jsx("h3",{className:"text-2xl font-bold mt-1","data-testid":"text-period-usage",children:o(h.totalTokens)})]}),e.jsx("div",{className:"p-2 bg-blue-50 dark:bg-blue-900/20 rounded-full",children:e.jsx(Ke,{className:"h-5 w-5 text-blue-600 dar
2k:text-blue-400"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2","data-testid":"text-daily-average",children:["Daily average: ",o(h.averageDaily)," credits"]})]})}),e.jsx(j,{"data-testid":"card-alltime-usage",children:e.jsxs(p,{className:"pt-6",children:[e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"All-Time Used"}),e.jsx("h3",{className:"text-2xl font-bold mt-1","data-testid":"text-alltime-usage",children:t?o(t.totalUsed):"0"})]}),e.jsx("div",{className:"p-2 bg-purple-50 dark:bg-purple-900/20 rounded-full",children:e.jsx(ts,{className:"h-5 w-5 text-purple-600 dark:text-purple-400"})})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2","data-testid":"text-highest-day",children:h.highestUsage.tokens>0?`Peak day: ${o(h.highestUsage.tokens)} credits`:"No usage recorded yet"})]})})]}),e.jsxs(Oe,{value:Ne,onValueChange:ve,className:"mb-8",children:[e.jsxs(_e,{className:"grid grid-cols-4 w-full max-w-lg mb-4","data-testid":"tabs-analytics",children:[e.jsx(I,{value:"usage","data-testid":"tab-usage",children:"Usage Trends"}),e.jsx(I,{value:"breakdown","data-testid":"tab-breakdown",children:"Breakdown"}),e.jsx(I,{value:"transactions","data-testid":"tab-transactions",children:"Transactions"}),e.jsx(I,{value:"rewards","data-testid":"tab-rewards",children:"Rewards"})]}),e.jsxs(G,{value:"usage",className:"space-y-6",children:[e.jsxs(j,{"data-testid":"card-usage-chart",children:[e.jsxs(N,{children:[e.jsx(v,{children:"Credit Usage Over Time"}),e.jsx(k,{children:"Daily credit consumption for the selected period"})]}),e.jsx(p,{children:e.jsx("div",{className:"h-[350px] sm:h-[400px]",children:De?e.jsx(_,{message:"Failed to load usage data. Please try again."}):c&&c.length>0?e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(ge,{data:c,margin:{top:10,right:10,left:0,bottom:0},children:[e.jsx(ae,{strokeDasharray:"3 3",vertical:!1,className:"stroke-border"}),e.jsx(te,{dataKey:"date",tickFormatter:s=>C(new Date(s),"MMM d"),tick:{fontSize:11},className:"fill-muted-foreground"}),e.jsx(re,{tick:{fontSize:11},tickFormatter:s=>s>=1e3?`${(s/1e3).toFixed(1)}k`:String(s),className:"fill-muted-foreground"}),e.jsx(B,{formatter:s=>[`${o(s)} credits`,"Usage"],labelFormatter:s=>C(new Date(s),"MMMM d, yyyy"),contentStyle:{borderRadius:"8px",border:"1px solid hsl(var(--border))",background:"hsl(var(--card))",color:"hsl(var(--card-foreground))"}}
2),e.jsx(je,{type:"monotone",dataKey:"tokens",stroke:"hsl(221, 83%, 53%)",fill:"hsl(221, 83%, 53%)",fillOpacity:.15,strokeWidth:2})]})}):e.jsx(M,{message:"No usage data available",sub:"Start using AI features to see your usage trends here."})})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(j,{"data-testid":"card-credit-sources",children:[e.jsxs(N,{children:[e.jsx(v,{children:"Credit Sources"}),e.jsx(k,{children:"Where your credits come from"})]}),e.jsxs(p,{children:[e.jsx("div",{className:"h-[280px]",children:O.length>0?e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(pe,{children:[e.jsx(fe,{data:O,cx:"50%",cy:"50%",innerRadius:70,outerRadius:110,dataKey:"tokens",nameKey:"source",label:({source:s,percentage:a})=>`${s}: ${a}%`,labelLine:!1,children:O.map((s,a)=>e.jsx(ue,{fill:s.color},`cell-${a}`))}),e.jsx(B,{formatter:s=>[`${o(s)} credits`,"Balance"],contentStyle:{borderRadius:"8px",border:"1px solid hsl(var(--border))",background:"hsl(var(--card))",color:"hsl(var(--card-foreground))"}})]})}):e.jsx(M,{message:"No credit source data"})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3 mt-4",children:O.map((s,a)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"text-sm truncate",children:[e.jsx("span",{className:"font-medium",children:s.source}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",S(R(s.tokens))," credits)"]})]})]},a))})]})]}),e.jsxs(j,{"data-testid":"card-usage-stats",children:[e.jsxs(N,{children:[e.jsx(v,{children:"Usage Statistics"}),e.jsx(k,{children:"Key metrics for the selected period"})]}),e.jsx(p,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/50",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Total Usage"}),e.jsxs("span",{className:"font-bold","data-testid":"text-stat-total",children:[S(R(h.totalTokens))," credits"]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2.5",children:e.jsx("div",{className:"bg-primary h-2.5 rounded-full w-full"})})]}),e.jsxs("div",{className:"p-4 rounded-lg border",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Daily Average"}),e.jsxs("span",{className:"font-bold","data-testid":"text-stat-average",children:[S(R(h.averageDaily))," credits"]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2.5",children:e.jsx("div",{className:"bg-green-600 h-2.5 rounded-full",style:{width:`${Math.min(100,h.totalTokens>0?h.averageDaily/h.totalTokens*100*c.length:0)}%`}})})]}),h.highestUsage.tokens>0&&e.jsxs("div",{className:"p-4 rounded-lg border",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Peak Usage Day"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:D(h.highestUsage.date)})]}),e.jsxs("span",{className:"font-bold","data-testid":"text-stat-peak",children:[S(R(h.highestUsage.tokens))," credits"]})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2.5",children:e.jsx("div",{className:"bg-amber-500 h-2.5 rounded-full w-full"})})]}),t&&e.jsxs("div",{className:"p-4 rounded-lg border",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("span",{className:"text-sm font-medium",children:"Current Balance"}),e.jsx("span",{className:"font-bold","data-testid":"text-stat-balance",children:S(t.credits??t.totalAvailable??0)})]}),e.jsx("div",{className:"w-full bg-muted rounded-full h-2.5",children:e.jsx("div",{className:"bg-indigo-600 h-2.5 rounded-full",style:{width:`${Math.min(100,(t.credits??t.totalAvailable??0)/((t.credits??t.totalAvailable??0)+h.totalTokens||1)*100)}%`}})})]})]})})]})]})]}),e.jsxs(G,{value:"breakdown",className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(j,{"data-testid":"card-category-pie",children:[e.jsxs(N,{children:[e.jsx(v,{children:"Usage by Feature"}),e.jsx(k,{children:"Credit consumption by AI feature"})]}),e.jsxs(p,{children:[e.jsx("div",{className:"h-[300px]",children:ne?e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsx(F,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):Se?e.jsx(_,{message:"Failed to load category data."}):i&&i.length>0?e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(pe,{children:[e.jsx(fe,{data:i,cx:"50%",cy:"50%",outerRadius:110,dataKey:"value",nameKey:"category",label:({category:s,percentage:a})=>`${s}: ${a}%`,children:i.map((s,a)=>e.jsx(ue,{fill:s.color||q[a%q.length]},`cell-${a}`))}),e.jsx(B,{formatter:s=>[`${o(s)} credits`,"Usage"],contentStyle:{borderRadius:"8px",border:"1px solid hsl(var(--border))",background:"hsl(var(--card))",color:"hsl(var(--card-foreground))"}})]})}):e.jsx(M,{message:"No category usage data",sub:"Use AI features to see breakdowns here."})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 mt-4",children:i==null?void 0:i.map((s,a)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:s.color}}),e.jsx("span",{className:"text-sm font-medium truncate",children:s.category}),e.jsx("span",{className:"text-sm text-muted-foreground ml-auto",children:o(s.value)})]},a))})]})]}),e.jsxs(j,{"data-testid":"card-consumption-bar",children:[e.jsxs(N,{children:[e.jsx(v,{children:"Daily Consumption"}),e.jsx(k,{children:"Credit usage by day"})]}),e.jsx(p,{children:e.jsx("div",{className:"h-[300px]",children:c&&c.length>0?e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(rs,{data:c,margin:{top:10,right:10,left:0,bottom:0},children:[e.jsx(ae,{strokeDasharray:"3 3",vertical:!1,className:"stroke-border"}),e.jsx(te,{dataKey:"date",tickFormatter:s=>C(new Date(s),"MMM d"),tick:{fontSize:11},className:"fill-muted-foreground"}),e.jsx(re,{tick:{fontSize:11}
2,tickFormatter:s=>s>=1e3?`${(s/1e3).toFixed(1)}k`:String(s),className:"fill-muted-foreground"}),e.jsx(B,{formatter:s=>[`${o(s)} credits`,"Usage"],labelFormatter:s=>C(new Date(s),"MMMM d, yyyy"),contentStyle:{borderRadius:"8px",border:"1px solid hsl(var(--border))",background:"hsl(var(--card))",color:"hsl(var(--card-foreground))"}}),e.jsx(ds,{dataKey:"tokens",fill:"hsl(221, 83%, 53%)",radius:[4,4,0,0]})]})}):e.jsx(M,{message:"No consumption data"})})})]})]}),e.jsxs(j,{"data-testid":"card-feature-table",children:[e.jsxs(N,{children:[e.jsx(v,{children:"Feature Utilization"}),e.jsx(k,{children:"Detailed credit usage by feature"})]}),e.jsx(p,{children:ne?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"md:hidden divide-y",children:i&&i.length>0?i.map((s,a)=>e.jsxs("div",{className:"p-4 space-y-2","data-testid":`card-category-${a}`,children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:s.color}}),s.category]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Credits Used"}),e.jsx("div",{children:o(s.value)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Sessions"}),e.jsx("div",{children:s.count})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Share"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-full max-w-[120px] bg-muted rounded-full h-2",children:e.jsx("div",{className:"h-2 rounded-full",style:{width:`${s.percentage}%`,backgroundColor:s.color}})}),e.jsxs("span",{className:"text-sm",children:[s.percentage,"%"]})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Last Used"}),e.jsx("div",{className:"text-sm",children:s.lastUsed?D(s.lastUsed):"N/A"})]})]})]},`m-${a}`)):e.jsx("div",{className:"text-center py-6 text-muted-foreground",children:"No feature usage data available"})}),e.jsx("div",{className:"hidden md:block w-full overflow-x-auto",children:e.jsxs(J,{children:[e.jsx(ee,{children:e.jsxs(T,{children:[e.jsx(m,{children:"Feature"}),e.jsx(m,{children:"Credits Used"}),e.jsx(m,{children:"Sessions"}),e.jsx(m,{children:"Share"}),e.jsx(m,{className:"text-right",children:"Last Used"})]})}),e.jsx(se,{children:i&&i.length>0?i.map((s,a)=>e.jsxs(T,{"data-testid":`row-category-${a}`,children:[e.jsx(l,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:s.color}}),s.category]})}),e.jsx(l,{children:o(s.value)}),e.jsx(l,{children:s.count}),e.jsx(l,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-full max-w-[80px] bg-muted rounded-full h-2",children:e.jsx("div",{className:"h-2 rounded-full",style:{width:`${s.percentage}%`,backgroundColor:s.color}})}),e.jsxs("span",{className:"text-sm",children:[s.percentage,"%"]})]})}),e.jsx(l,{className:"text-right text-sm text-muted-foreground",children:s.lastUsed?D(s.lastUsed):"N/A"})]},a)):e.jsx(T,{children:e.jsx(l,{colSpan:5,className:"text-center py-6 text-muted-foreground",children:"No feature usage data available"})})})]})})]})})]})]}),e.jsxs(G,{value:"transactions",className:"space-y-6",children:[e.jsxs(j,{"data-testid":"card-transactions",children:[e.jsxs(N,{children:[e.jsx(v,{children:"Credit Transactions"}),e.jsx(k,{children:"History of credit additions and usage"})]}),e.jsx(p,{children:Ue?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):Me?e.jsx(_,{message:"Failed to load transactions."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"md:hidden divide-y",children:z.length>0?z.map(s=>{var a,r,n,u;return e.jsxs("div",{className:"p-4 space-y-2","data-testid":`card-tx-${s.id}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm",children:D(s.transactionDate||"")}),e.jsx(P,{variant:"outline",className:ce(s),children:le(s)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:s.transactionAmount>0?"text-foreground font-medium":"text-muted-foreground",children:xe(s)}),e.jsx(P,{variant:s.transactionStatus==="success"?"outline":"secondary",className:me(s.transactionStatus),children:oe(s.transactionStatus)})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[(r=(a=s.orderDetail)==null?void 0:a.packageDetails)!=null&&r.name?s.orderDetail.packageDetails.name:s.paymentGateway?s.paymentGateway.charAt(0).toUpperCase()+s.paymentGateway.slice(1):"â",(u=(n=s.orderDetail)==null?void 0:n.packageDetails)!=null&&u.tokens?` · ${S(R(s.orderDetail.packageDetails.tokens))} credits`:""]})]},`m-${s.id}`)}):e.jsx("div",{className:"text-center py-6 text-muted-foreground",children:"No transactions foun
2d for this period"})}),e.jsx("div",{className:"hidden md:block w-full overflow-x-auto",children:e.jsxs(J,{children:[e.jsx(ee,{children:e.jsxs(T,{children:[e.jsx(m,{children:"Date"}),e.jsx(m,{children:"Type"}),e.jsx(m,{children:"Amount"}),e.jsx(m,{children:"Status"}),e.jsx(m,{className:"text-right",children:"Details"})]})}),e.jsx(se,{children:z.length>0?z.map(s=>{var a,r,n,u;return e.jsxs(T,{"data-testid":`row-tx-${s.id}`,children:[e.jsx(l,{className:"text-sm",children:D(s.transactionDate||"")}),e.jsx(l,{children:e.jsx(P,{variant:"outline",className:ce(s),"data-testid":`badge-tx-type-${s.id}`,children:le(s)})}),e.jsx(l,{children:e.jsx("span",{className:s.transactionAmount>0?"text-foreground font-medium":"text-muted-foreground",children:xe(s)})}),e.jsx(l,{children:e.jsx(P,{variant:s.transactionStatus==="success"?"outline":"secondary",className:me(s.transactionStatus),"data-testid":`badge-tx-status-${s.id}`,children:oe(s.transactionStatus)})}),e.jsxs(l,{className:"text-right text-sm text-muted-foreground",children:[(r=(a=s.orderDetail)==null?void 0:a.packageDetails)!=null&&r.name?s.orderDetail.packageDetails.name:s.paymentGateway?s.paymentGateway.charAt(0).toUpperCase()+s.paymentGateway.slice(1):"â",(u=(n=s.orderDetail)==null?void 0:n.packageDetails)!=null&&u.tokens?` · ${S(R(s.orderDetail.packageDetails.tokens))} credits`:""]})]},s.id)}):e.jsx(T,{children:e.jsx(l,{colSpan:5,className:"text-center py-6 text-muted-foreground",children:"No transactions found for this period"})})})]})})]})}),$&&$.totalPages>1&&e.jsxs(ze,{className:"flex items-center justify-between border-t px-6 py-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground","data-testid":"text-tx-pagination",children:["Page ",$.page," of ",$.totalPages," (",$.total," total)"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Z,{variant:"outline",size:"sm",disabled:K<=1,onClick:()=>W(s=>Math.max(1,s-1)),"data-testid":"button-tx-prev",children:[e.jsx(ns,{className:"h-4 w-4 mr-1"})," Previous"]}),e.jsxs(Z,{variant:"outline",size:"sm",disabled:K>=$.totalPages,onClick:()=>W(s=>s+1),"data-testid":"button-tx-next",children:["Next ",e.jsx(He,{className:"h-4 w-4 ml-1"})]})]})]})]}),e.jsxs(j,{"data-testid":"card-balance-history",children:[e.jsxs(N,{children:[e.jsx(v,{children:"Credit Balance History"}),e.jsx(k,{children:"How your credit balance changed over time"})]}),e.jsx(p,{children:e.jsx("div",{className:"h-[300px]",children:Te?e.jsx("div",{className:"h-full flex items-center justify-center",children:e.jsx(F,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):Ae?e.jsx(_,{message:"Failed to load balance history."}):Q&&Q.length>0?e.jsx(E,{width:"100%",height:"100%",children:e.jsxs(ge,{data:Q,margin:{top:10,right:10,left:0,bottom:0},children:[e.jsx(ae,{strokeDasharray:"3 3",vertical:!1,className:"stroke-border"}),e.jsx(te,{dataKey:"date",tickFormatter:s=>C(new Date(s),"MMM d"),tick:{fontSize:11},className:"fill-muted-foreground"}),e.jsx(re,{tick:{fontSize:11},tickFormatter:s=>s>=1e3?`${(s/1e3).toFixed(1)}k`:String(Math.round(s)),className:"fill-muted-foreground"}),e.jsx(B,{formatter:s=>[`${o(s)} credits`,"Balance"],labelFormatter:s=>C(new Date(s),"MMMM d, yyyy"),contentStyle:{borderRadius:"8px",border:"1px solid hsl(var(--border))",background:"hsl(var(--card))",color:"hsl(var(--card-foreground))"}}),e.jsx(je,{type:"monotone",dataKey:"balance",stroke:"hsl(160, 84%, 39%)",fill:"hsl(160, 84%, 39%)",fillOpacity:.15,strokeWidth:2})]})}):e.jsx(M,{message:"No balance history available"})})})]})]}),e.jsx(G,{value:"rewards",className:"space-y-6",children:e.jsxs(j,{"data-testid":"card-rewards",children:[e.jsx(N,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx(v,{children:"Credit Rewards & Bonuses"}),e.jsx(k,{children:"Credits earned through rewards, bonuses, and admin additions"})]}),H.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{className:"h-4 w-4 text-green-600 dark:text-green-400"}),e.jsxs("span",{className:"text-sm font-medium text-green-600 dark:text-green-400","data-testid":"text-total-rewards",children:["Total: ",o(H.reduce((s,a)=>
2s+a.credits,0))," credits earned"]})]})]})}),e.jsx(p,{children:$e?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):H.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(J,{children:[e.jsx(ee,{children:e.jsxs(T,{children:[e.jsx(m,{children:"Date"}),e.jsx(m,{children:"Type"}),e.jsx(m,{children:"Credits"}),e.jsx(m,{children:"Description"}),e.jsx(m,{className:"text-right",children:"Balance After"})]})}),e.jsx(se,{children:H.map(s=>e.jsxs(T,{"data-testid":`row-reward-${s.id}`,children:[e.jsx(l,{className:"text-sm",children:D(s.createdAt)}),e.jsx(l,{children:e.jsxs(P,{variant:"secondary",className:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900/30 dark:text-emerald-400","data-testid":`badge-reward-type-${s.id}`,children:[e.jsx(Ie,{className:"h-3 w-3 mr-1"}),ie(s.type)]})}),e.jsx(l,{children:e.jsxs("span",{className:"text-green-600 dark:text-green-400 font-medium","data-testid":`text-reward-credits-${s.id}`,children:["+",o(s.credits)]})}),e.jsx(l,{className:"text-sm text-muted-foreground max-w-[200px] truncate",children:s.description}),e.jsx(l,{className:"text-right text-sm text-muted-foreground",children:s.balanceAfter!==null?`${o(s.balanceAfter)} credits`:"â"})]},s.id))})]})}):e.jsx(M,{message:"No rewards earned yet",sub:"Complete your profile, refer colleagues, or earn bonuses to see rewards here."})})]})})]})]})}export{Ss as default};
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.