1import{g as M,r as S,D as T,j as e,y as a,K as n,z as l,M as i,F as k,N as j}from"./index-Cn6AmDcL.js";import{S as C,a as A,b as F,c as I,d as x}from"./select-D_Og1CQU.js";import{P as D}from"./PortalLayout-dTp8A7HO.js";import{D as R}from"./dollar-sign-Dty9oKd_.js";import{A as L}from"./activity-DWQrncT3.js";import{T as $}from"./trending-up-Cr2WWT_o.js";import{T as G}from"./trending-down-Ca1gV7Ee.js";import{C as V}from"./chart-column-DfgFWH0z.js";import{R as g,A as z,C as f,X as u,Y as N,T as b,b as K,B as U}from"./AreaChart-DzIZmuvP.js";import{B}from"./BarChart-043V9PD8.js";import{S as P}from"./store-DO2LCPff.js";import"./index-z78jIqtN.js";import"./index-DZLNPIfk.js";import"./Combination-C5NQgvtu.js";import"./check-MEE_Y30Z.js";import"./chevron-right-BJ8sUSaj.js";import"./building-2-DrNJVm54.js";import"./users-CGeCGLTU.js";import"./log-out-dYcCBA_p.js";import"./isEqual-DreOScp5.js";/** 2 * @license lucide-react v0.453.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const E=M("ArrowDownRight",[["path",{d:"m7 7 10 10",key:"1fmybs"}],["path",{d:"M17 7v10H7",key:"6fjiku"}]]);function o(r){return new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(r)}function w(r){return r>=1e6?`$${(r/1e6).toFixed(1)}M`:r>=1e3?`$${(r/1e3).toFixed(1)}K`:o(r)}function d(r){const[h,c]=r.split("-");return new Date(parseInt(h),parseInt(c)-1).toLocaleDateString("en-US",{month:"short",year:"2-digit"})}function me(){const[r,h]=S.useState("12"),{data:c,isLoading:y,error:v}=T({queryKey:["/api/portal/analytics/residuals",r],queryFn:async()=>{const t=await fetch(`/api/portal/analytics/residuals?months=${r}`,{credentials:"include"});if(!t.ok)throw new Error("Failed to fetch analytics");return t.json()}}),s=c==null?void 0:c.analytics;return e.jsx(D,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Residual Analytics"}),e.jsx("p",{className:"text-gray-600",children:"Track income trends, growth, and top-performing merchants"})]}),e.jsxs(C,{value:r,onValueChange:h,children:[e.jsx(A,{className:"w-[180px]",children:e.jsx(F,{placeholder:"Select time range"})}),e.jsxs(I,{children:[e.jsx(x,{value:"3",children:"Last 3 Months"}),e.jsx(x,{value:"6",children:"Last 6 Months"}),e.jsx(x,{value:"12",children:"Last 12 Months"}),e.jsx(x,{value:"24",children:"Last 24 Months"})]})]})]}),y?e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[1,2,3,4].map(t=>e.jsxs(a,{className:"animate-pulse",children:[e.jsx(n,{className:"pb-2",children:e.jsx("div",{className:"h-4 bg-gray-200 rounded w-24"})}),e.jsx(l,{children:e.jsx("div",{className:"h-8 bg-gray-200 rounded w-32"})})]},t))}):v?e.jsx(a,{className:"bg-red-50 border-red-200",children:e.jsx(l,{className:"pt-6",children:e.jsx("p",{className:"text-red-600",children:"Failed to load analytics data. Please try again."})})}):s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[e.jsxs(a,{children:[e.jsxs(n,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(i,{className:"text-sm font-medium text-gray-600",children:"Total Income"}),e.jsx(R,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(l,{children:[e.jsx("div",{className:"text-2xl font-bold text-gray-900",children:o(s.summary.totalIncome)}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[s.summary.monthsAnalyzed," months analyzed"]})]})]}),e.jsxs(a,{children:[e.jsxs(n,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(i,{className:"text-sm font-medium text-gray-600",children:"Avg Monthly Income"}),e.jsx(L,{className:"h-4 w-4 text-blue-600"})]}),e.jsxs(l,{children:[e.jsx("div",{className:"text-2xl font-bold text-gray-900",children:o(s.summary.avgMonthlyIncome)}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"per month average"})]})]}),e.jsxs(a,{children:[e.jsxs(n,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(i,{className:"text-sm font-medium text-gray-600",children:"Month-over-Month"}),s.summary.momGrowth>=0?e.jsx($,{className:"h-4 w-4 text-green-600"}):e.jsx(G,{className:"h-4 w-4 text-red-600"})]}),e.jsxs(l,{children:[e.jsxs("div",{className:`text-2xl font-bold flex items-center gap-1 ${s.summary.momGrowth>=0?"text-green-600":"text-red-600"}`,children:[s.summary.momGrowth>=0?e.jsx(k,{className:"h-5 w-5"}):e.jsx(E,{className:"h-5 w-5"}),Math.abs(s.summary.momGrowth).toFixed(1),"%"]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"vs previous month"})]})]}),e.jsxs(a,{children:[e.jsxs(n,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(i,{className:"text-sm font-medium text-gray-600",children:"Total Volume"}),e.jsx(V,{className:"h-4 w-4 text-purple-600"})]}),e.jsxs(l,{children:[e.jsx("div",{className:"text-2xl font-bold text-gray-900",children:w(s.summary.totalVolume)}),e.jsxs("p",{className:"text-xs text-gray-500 mt-1",children:[s.summary.totalTransactions.toLocaleStr
6ing()," transactions"]})]})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(a,{children:[e.jsxs(n,{children:[e.jsx(i,{className:"text-lg",children:"Income Trend"}),e.jsx(j,{children:"Monthly residual income over time"})]}),e.jsx(l,{children:e.jsx("div",{className:"h-[300px]",children:s.monthlyTrend.length>0?e.jsx(g,{width:"100%",height:"100%",children:e.jsxs(z,{data:s.monthlyTrend,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"incomeGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#10b981",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"#10b981",stopOpacity:0})]})}),e.jsx(f,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),e.jsx(u,{dataKey:"month",tickFormatter:d,stroke:"#6b7280",fontSize:12}),e.jsx(N,{tickFormatter:t=>`$${t}`,stroke:"#6b7280",fontSize:12}),e.jsx(b,{formatter:t=>[o(t),"Income"],labelFormatter:d,contentStyle:{borderRadius:"8px",border:"1px solid #e5e7eb"}}),e.jsx(K,{type:"monotone",dataKey:"income",stroke:"#10b981",strokeWidth:2,fill:"url(#incomeGradient)"})]})}):e.jsx("div",{className:"h-full flex items-center justify-center text-gray-500",children:"No data available for the selected period"})})})]}),e.jsxs(a,{children:[e.jsxs(n,{children:[e.jsx(i,{className:"text-lg",children:"Volume Trend"}),e.jsx(j,{children:"Monthly transaction volume over time"})]}),e.jsx(l,{children:e.jsx("div",{className:"h-[300px]",children:s.monthlyTrend.length>0?e.jsx(g,{width:"100%",height:"100%",children:e.jsxs(B,{data:s.monthlyTrend,children:[e.jsx(f,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),e.jsx(u,{dataKey:"month",tickFormatter:d,stroke:"#6b7280",fontSize:12}),e.jsx(N,{tickFormatter:t=>w(t),stroke:"#6b7280",fontSize:12}),e.jsx(b,{formatter:t=>[o(t),"Volume"],labelFormatter:d,contentStyle:{borderRadius:"8px",border:"1px solid #e5e7eb"}}),e.jsx(U,{dataKey:"volume",fill:"#8b5cf6",radius:[4,4,0,0]})]})}):e.jsx("div",{className:"h-full flex items-center justify-center text-gray-500",children:"No data available for the selected period"})})})]})]}),e.jsxs(a,{children:[e.jsxs(n,{children:[e.jsxs(i,{className:"text-lg flex items-center gap-2",children:[e.jsx(P,{className:"h-5 w-5 text-blue-600"}),"Top Performing Merchants"]}),e.jsx(j,{children:"Merchants ranked by total residual income"})]}),e.jsx(l,{children:s.topMerchants.length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200",children:[e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-600",children:"Rank"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-600",children:"Merchant"}),e.jsx("th",{className:"text-left py-3 px-4 text-sm font-medium text-gray-600",children:"MID"}),e.jsx("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-600",children:"Total Income"}),e.jsx("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-600",children:"Total Volume"}),e.jsx("th",{className:"text-right py-3 px-4 text-sm font-medium text-gray-600",children:"Months Active"})]})}),e.jsx("tbody",{children:s.topMerchants.map((t,m)=>{var p;return e.jsxs("tr",{className:"border-b border-gray-100 hover:bg-gray-50",children:[e.jsx("td",{className:"py-3 px-4",children:e.jsx("span",{className:`inline-flex items-center justify-center w-6 h-6 rounded-full text-xs font-bold ${m===0?"bg-yellow-100 text-yellow-800":m===1?"bg-gray-100 text-gray-800":m===2?"bg-orange-100 text-orange-800":"bg-gray-50 text-gray-600"}`,children:m+1})}),e.jsx("td",{className:"py-3 px-4 font-medium text-gray-900",children:t.name}),e.jsx("td",{className:"py-3 px-4 text-gray-600 font-mono text-sm",children:(p=t.mid)!=null&&p.startsWith("hs-")?e.jsx("span",{className:"text-gray-400",children:"â"}):t.mid}),e.jsx("td",{className:"py-3 px-4 text-right font-semibold text-green-600",children:o(t.totalIncome)}),e.jsx("td",{className:"py-3 px-4 text-right text-gray-600",children:o(t.totalVolume)}),e.jsx("td",{className:"py-3 px-4 text-right text-gray-600",children:t.months})]},t.mid)})})]})}):e.jsx("div",{className:"text-center py-8 text-gray-500",children:"No merchant data available for the selected period"})})]})]}):null]})})}export{me 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.