PageSourceSearch

https://1325.ai/assets/SalesAgentDashboardPage-CmslnnAU.js

js 1325.ai collected 2026-10-05 13:12:41 UTC 40,444 bytes, 1 lines download raw bytes

1import{j as e}from"./ui-vendor-CEJ8_wX2.js";import{r as s,e as t}from"./react-vendor-DWXAA69x.js";import{C as r,i as a,j as n,z as o,m as l,D as d,aa as i,U as c,k as m,y as x,x as u,G as h,an as f,B as g,am as j,al as b,d as p,a_ as y,O as N,n as v,a$ as w,b0 as k,$ as _,b1 as C,K as D,o as S,s as F,h as M,H as $,b2 as R,b3 as T,a1 as L,a2 as E,a3 as P,at as A}from"./index-BiVZYF0p.js";import{u as O}from"./use-sales-agent-DIRPH7Gu.js";import{R as z}from"./ResponsiveLayout-BlqydHj8.js";import{C as B}from"./calendar-B5xJjzgU.js";import{f as Y}from"./format-bK106qf4.js";import{U as V}from"./user-plus-BqE9WCUn.js";import{T as H,a as K,b as q,c as U,d as W,e as I}from"./table-SubQihu-.js";import{f as G,c as J,d as X,h as Q,i as Z,j as ee}from"./sales-agent-api-CZDflxJQ.js";import{R as se,L as te,C as re,X as ae,Y as ne,T as oe,f as le,a as de,B as ie,e as ce}from"./charts-CkMHw2ev.js";import{A as me}from"./arrow-down-right-BRxALXIu.js";import{A as xe}from"./arrow-up-right-DEG-0mRI.js";import{R as ue}from"./receipt-DRx2ZnFE.js";import{C as he}from"./calendar-CskyYsFE.js";import{e as fe,a as ge,b as je,c as be}from"./export-utils-YYsMcutE.js";import{F as pe}from"./file-spreadsheet-CCBvzAGj.js";import{C as ye}from"./copy-3yAHZG-6.js";import"./supabase-BPE9t49R.js";import"./admin-heavy-CCv53o_I.js";import"./animation-B0AhmLf0.js";import"./query-vendor-e1oLGoso.js";import"./startOfMonth-_Kv6s8Ri.js";import"./addMonths-C4SMFuwm.js";import"./isSameMonth-BelR8mbH.js";import"./isBefore-CYH7ZQGp.js";import"./isSameDay-BNvPu1n2.js";import"./addDays-DjueVErr.js";import"./subDays-vl1Fdbkr.js";import"./addWeeks-B6uB6QFE.js";import"./addYears-Be1XjDEq.js";import"./endOfWeek-Cn0OjFMi.js";import"./chevron-left-MXoHjiFl.js";import"./pdfLogo-DtkfA7IN.js";const Ne=({totalReferrals:s,totalEarned:t,pendingCommissions:m,recruitedAgents:x,tier:u})=>{const h={bronze:"text-orange-600 dark:text-orange-400",silver:"text-slate-400 dark:text-slate-300",gold:"text-yellow-500 dark:text-yellow-400",platinum:"text-purple-600 dark:text-purple-400"},f=h[u.toLowerCase()]||h.bronze;return e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 lg:gap-6",children:[e.jsxs(r,{className:"glass-card hover-lift border-border/50 group",children:[e.jsxs(a,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(n,{className:"text-sm font-body font-medium text-muted-foreground",children:"Current Tier"}),e.jsx(o,{className:"h-5 w-5 text-primary/60 transition-transform group-hover:scale-110"})]}),e.jsxs(l,{children:[e.jsx("div",{className:`text-3xl font-display font-bold ${f} capitalize`,children:u}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 font-body",children:[s," lifetime referrals"]})]})]}),e.jsxs(r,{className:"glass-card hover-lift border-border/50 group",children:[e.jsxs(a,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(n,{className:"text-sm font-body font-medium text-muted-foreground",children:"Total Earned"}),e.jsx(d,{className:"h-5 w-5 text-primary/60 transition-transform group-hover:scale-110"})]}),e.jsxs(l,{children:[e.jsxs("div",{className:"text-3xl font-display font-bold text-green-600 dark:text-green-400",children:["$",t.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-body",children:"All-time earnings"})]})]}),e.jsxs(r,{className:"glass-card hover-lift border-border/50 group",children:[e.jsxs(a,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(n,{className:"text-sm font-body font-medium text-muted-foreground",children:"Pending"}),e.jsx(i,{className:"h-5 w-5 text-primary/60 transition-transform group-hover:scale-110"})]}),e.jsxs(l,{children:[e.jsxs("div",{className:"text-3xl font-display font-bold text-orange-600 dark:text-orange-400",children:["$",m.toFixed(2)]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-body",children:"Awaiting payment"})]})]}),e.jsxs(r,{className:"glass-card hover-lift border-border/50 group",children:[e.jsxs(a,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(n,{className:"text-sm font-body font-medium text-muted-foreground",children:"Team Size"}),e.jsx(c,{className:"h-5 w-5 text-primary/60 transition-transform group-hover:scale-110"})]}),e.jsxs(l,{children:[e.jsx("div",{className:"text-3xl font-display font-bold text-blue-600 dar
1k:text-blue-400",children:x}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 font-body",children:"Recruited agents"})]})]})]})},ve=({referrals:s,isLoading:t})=>{const o=e=>{switch(e.toLowerCase()){case"paid":return"bg-green-500/10 text-green-600 dark:text-green-400 border-green-500/20";case"pending":return"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 border-yellow-500/20";case"due":return"bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20";default:return"bg-muted/30 text-muted-foreground border-border/50"}};return t?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Business Referrals"}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Loading your referrals..."})]}),e.jsx(l,{children:e.jsx("div",{className:"space-y-3",children:[1,2,3].map(s=>e.jsx("div",{className:"h-20 bg-muted/30 animate-pulse rounded-lg"},s))})})]}):0===s.length?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Business Referrals"}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Your referrals will appear here"})]}),e.jsx(l,{children:e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(x,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{className:"font-body",children:"No referrals yet. Share your referral code to get started!"})]})})]}):e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Business Referrals"}),e.jsxs(m,{className:"font-body text-muted-foreground",children:[s.length," total referral",1!==s.length?"s":""]})]}),e.jsx(l,{children:e.jsx("div",{className:"space-y-3",children:s.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-4 border border-border/50 rounded-lg hover:bg-muted/20 transition-all hover-lift group",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(x,{className:"h-4 w-4 text-primary/60 transition-transform group-hover:scale-110"}),e.jsx("h4",{className:"font-display font-semibold text-foreground",children:s.businesses?.business_name||"Business"}),e.jsx(u,{className:`${o(s.commission_status)} font-body border`,children:s.commission_status})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground font-body",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(B,{className:"h-3 w-3"}),Y(new Date(s.referral_date),"MMM d, yyyy")]}),s.businesses?.city&&e.jsxs("span",{children:[s.businesses.city,", ",s.businesses.state]})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"flex items-center gap-1 text-lg font-display font-bold text-green-600 dark:text-green-400",children:[e.jsx(d,{className:"h-4 w-4"}),s.commission_amount.toFixed(2)]}),e.jsxs("div",{className:"text-xs text-muted-foreground font-body",children:["on $",s.subscription_amount," sub"]})]})]},s.id))})})]})},we=({directCommissions:s,teamOverrides:t,recruitmentBonuses:i,totalEarnings:x})=>{const u=e=>x>0?e/x*100:0,g=[{label:"Direct Commissions",amount:s,percentage:u(s),icon:d,color:"text-green-500 dark:text-green-400",bgColor:"bg-green-500/10"},{label:"Team Overrides",amount:t,percentage:u(t),icon:c,color:"text-blue-500 dark:text-blue-400",bgColor:"bg-blue-500/10"},{label:"Recruitment Bonuses",amount:i,percentage:u(i),icon:h,color:"text-purple-500 dark:text-purple-400",bgColor:"bg-purple-500/10"}];return e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-2xl font-display font-semibold text-foreground",children:"Earnings Breakdown"}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Your income by source"})]}),e.jsxs(l,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx(o,{className:"h-6 w-6 text-green-500 dark:text-green-400"}),e.jsxs("span",{className:"text-4xl font-display font-bold text-foreground",children:["$",x.toFixed(2)]}),e.jsx("span",{className:"text-muted-foreground font-body",children:"total"})]}),e.jsx("div",{className:"space-y-4",children:g.map(s=>{const t=s.icon;return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`p-2.5 rounded-lg ${s.bgColor} transition-transform group-hover:scale-110`,children:e.jsx(t,{className:`h-4 w-4 ${s.color}`})}),e.jsx("span",{className:"text-sm font-body font-medium text-foreground",children:s.label})]}),e.jsxs("span",{className:"font-display font-bold text-foreground",children:["$",s.amount.toFixed(2)]})]}),e.jsx(f,{value:s.percentage,className:"h-2 bg-muted/30"}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1 font-body",children:[s.percentage.toFixed(1),"% of total earnings"]})]},s.label)})}),0===x&&e.jsx("div",{className:"text-center py-4 text-muted-foreground",children:e.jsx("p",{className:"text-sm font-body",children:"No earnings yet. Start referring businesses!"})})]})]})},ke=({recruitedAgents:s,teamOverrides:t,isLoading:d})=>{const i=t.reduce((e,s)=>e+parseFloat(s.override_amount||0),0);
1return d?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Your Team"}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Loading team data..."})]}),e.jsx(l,{children:e.jsx("div",{className:"h-40 bg-muted/30 animate-pulse rounded-lg shimmer"})})]}):0===s.length?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Your Team"}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Recruit agents to build your team"})]}),e.jsx(l,{children:e.jsxs("div",{className:"text-center py-12 space-y-4",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-muted/30 mb-2",children:e.jsx(c,{className:"h-8 w-8 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-body text-foreground font-medium",children:"No team members yet"}),e.jsx("p",{className:"text-sm text-muted-foreground font-body max-w-md mx-auto",children:"Share your recruiter code when inviting new agents to earn $75 bonuses and 7.5% overrides!"})]}),e.jsxs(g,{className:"gap-2 mt-4",children:[e.jsx(V,{className:"h-4 w-4"}),"Invite Agents"]})]})})]}):e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Your Team"}),e.jsxs(m,{className:"font-body text-muted-foreground",children:[s.length," agent",1!==s.length?"s":""," • $",i.toFixed(2)," in overrides"]})]}),e.jsx(l,{children:e.jsx("div",{className:"space-y-3",children:s.map(s=>{const r=t.filter(e=>e.recruited_agent_id===s.id).reduce((e,s)=>e+parseFloat(s.override_amount||0),0);return e.jsxs("div",{className:"flex items-center justify-between p-4 border border-border/50 rounded-lg hover:bg-muted/20 transition-all hover-lift group",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h4",{className:"font-display font-semibold text-foreground",children:s.full_name}),e.jsx(u,{variant:"outline",className:"font-body",children:s.referral_code})]}),e.jsxs("div",{className:"flex items-center gap-4 text-sm text-muted-foreground font-body",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(B,{className:"h-3 w-3"}),"Joined ",Y(new Date(s.created_at),"MMM yyyy")]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(o,{className:"h-3 w-3"}),s.total_referrals||0," referrals"]})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"text-lg font-display font-bold text-purple-600 dark:text-purple-400",children:["$",r.toFixed(2)]}),e.jsx("div",{className:"text-xs text-muted-foreground font-body",children:"Your overrides"})]})]},s.id)})})})]})},_e=({commissions:s,isLoading:t})=>t?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Commission History"}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Loading commissions..."})]}),e.jsx(l,{children:e.jsx("div",{className:"h-64 bg-muted/30 animate-pulse rounded-lg"})})]}):0===s.length?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Commission History"}),e.jsx(m,{className:"font-body text-muted-foreground",children:"No commission records yet"})]}),e.jsx(l,{children:e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(d,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{className:"font-body",children:"Your commission history will appear here"})]})})]}):e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Commission History"}),e.jsxs(m,{className:"font-body text-muted-foreground",children:[s.length," commission",1!==s.length?"s":""]})]}),e.jsx(l,{children:e.jsx("div",{className:"rounded-lg border border-border/50 overflow-hidden",children:e.jsxs(H,{
1children:[e.jsx(K,{children:e.jsxs(q,{className:"bg-muted/30 hover:bg-muted/40",children:[e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Amount"}),e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Status"}),e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Due Date"}),e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Paid Date"}),e.jsx(U,{className:"text-right font-body font-semibold text-foreground",children:"Details"})]})}),e.jsx(W,{children:s.map(s=>{return e.jsxs(q,{className:"hover:bg-muted/20 transition-colors",children:[e.jsxs(I,{className:"font-display font-bold text-green-600 dark:text-green-400",children:["$",s.amount.toFixed(2)]}),e.jsx(I,{children:e.jsx(u,{className:`${t=s.status,{pending:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 border-yellow-500/20",paid:"bg-green-500/10 text-green-600 dark:text-green-400 border-green-500/20",due:"bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20",cancelled:"bg-red-500/10 text-red-600 dark:text-red-400 border-red-500/20"}[t.toLowerCase()]||"bg-muted/30 text-muted-foreground border-border/50"} font-body border`,children:s.status})}),e.jsx(I,{children:e.jsxs("div",{className:"flex items-center gap-1 text-sm font-body",children:[e.jsx(i,{className:"h-3 w-3 text-muted-foreground"}),Y(new Date(s.due_date),"MMM d, yyyy")]})}),e.jsx(I,{children:s.paid_date?e.jsxs("div",{className:"flex items-center gap-1 text-sm font-body",children:[e.jsx(B,{className:"h-3 w-3 text-muted-foreground"}),Y(new Date(s.paid_date),"MMM d, yyyy")]}):e.jsx("span",{className:"text-muted-foreground text-sm font-body",children:"-"})}),e.jsx(I,{className:"text-right text-sm text-muted-foreground font-body",children:s.referrals?.subscription_amount&&e.jsxs("span",{children:["on $",s.referrals.subscription_amount," sub"]})})]},s.id);var t})})]})})})]}),Ce=({agentId:t})=>{const[d,i]=s.useState(null),[c,x]=s.useState(!0);s.useEffect(()=>{h()},[t]);const h=async()=>{try{const e=await G(t);i(e)}catch(e){}finally{x(!1)}};if(c)return e.jsxs(r,{children:[e.jsx(a,{children:e.jsx(n,{children:"Tier Progress"})}),e.jsx(l,{children:e.jsx("div",{className:"h-32 bg-muted animate-pulse rounded"})})]});if(!d)return null;const g=(e=>{switch(e.toLowerCase()){case"platinum":return{commission:"15%",override:"7.5%",bonus:"$100",requirements:"50+ referrals"};case"gold":return{commission:"12.5%",override:"7.5%",bonus:"$75",requirements:"25-49 referrals"};case"silver":return{commission:"11%",override:"7.5%",bonus:"$75",requirements:"10-24 referrals"};default:return{commission:"10%",override:"7.5%",bonus:"$75",requirements:"0-9 referrals"}}})(d.current_tier),y="platinum"===d.current_tier.toLowerCase();return e.jsxs(r,{children:[e.jsxs(a,{children:[e.jsxs(n,{className:"flex items-center gap-2",children:[(s=>{switch(s.toLowerCase()){case"platinum":return e.jsx(p,{className:"h-5 w-5"});case"gold":return e.jsx(j,{className:"h-5 w-5"});case"silver":return e.jsx(b,{className:"h-5 w-5"});default:return e.jsx(o,{className:"h-5 w-5"})}})(d.current_tier),"Tier Progress"]}),e.jsx(m,{children:"Upgrade your tier by referring more businesses"})]}),e.jsxs(l,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Current Tier"}),e.jsx(u,{className:`${(e=>{switch(e.toLowerCase()){case"platinum":return"text-purple-600 bg-purple-100";case"gold":return"text-yellow-600 bg-yellow-100";case"silver":return"text-gray-500 bg-gray-100";default:return"text-amber-700 bg-amber-100"}})(d.current_tier)} text-lg py-1 px-3 capitalize`,children:d.current_tier})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Commission Rate"}),e.jsx("p",{className:"text-2xl font-bold text-primary",children:g.commission})]})]}),!y&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Progress to ",d.next_tier]}),e.jsxs("span",{className:"font-medium",children:[d.current_referrals," / ",d.next_tier_threshold," referrals"]})]}),e.jsx(f,{value:Number(d.progress_percentage),className:"h-3"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[d.next_tier_threshold-d.current_referrals," more referrals needed"]})]}),y&&e.jsxs("div",{className:"text-center py-4 bg-primary/5 rounded-lg",children:[e.jsx(j,{className:"h-8 w-8 mx-auto mb-2 text-primary"}),e.jsx("p",{className:"font-medium text-primary",children:"You've reached the highest tier!"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Keep referring to maximize your earnings"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 pt-4 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Team Override"}),e.jsx("p",{className:"text-sm font-semibold",children:g.override})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Recruitment Bonus"}),e.jsx("p",{className:"text-sm font-semibold",children:g.bonus})]})]})]})]})}
1,De=({commissions:s,teamOverrides:t,recruitmentBonuses:d})=>{const i=(()=>{const e={};return s.forEach(s=>{if("paid"===s.status&&s.paid_date){const t=new Date(s.paid_date).toLocaleDateString("en-US",{year:"numeric",month:"short"});e[t]||(e[t]={month:t,direct:0,overrides:0,bonuses:0}),e[t].direct+=parseFloat(s.amount)}}),t.forEach(s=>{if("paid"===s.status&&s.earned_date){const t=new Date(s.earned_date).toLocaleDateString("en-US",{year:"numeric",month:"short"});e[t]||(e[t]={month:t,direct:0,overrides:0,bonuses:0}),e[t].overrides+=parseFloat(s.override_amount)}}),d.forEach(s=>{if("paid"===s.status&&s.earned_date){const t=new Date(s.earned_date).toLocaleDateString("en-US",{year:"numeric",month:"short"});e[t]||(e[t]={month:t,direct:0,overrides:0,bonuses:0}),e[t].bonuses+=parseFloat(s.bonus_amount)}}),Object.values(e).sort((e,s)=>new Date(e.month).getTime()-new Date(s.month).getTime())})();return 0===i.length?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsxs(n,{className:"flex items-center gap-2 text-xl font-display font-semibold text-foreground",children:[e.jsx(o,{className:"h-5 w-5 text-primary/60"}),"Earnings Trend"]}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Track your earnings over time"})]}),e.jsx(l,{children:e.jsx("div",{className:"flex items-center justify-center h-[300px] text-muted-foreground font-body",children:"No earnings data available yet"})})]}):e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsxs(n,{className:"flex items-center gap-2 text-xl font-display font-semibold text-foreground",children:[e.jsx(o,{className:"h-5 w-5 text-primary/60"}),"Earnings Trend"]}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Track your earnings over time by category"})]}),e.jsx(l,{children:e.jsx(se,{width:"100%",height:300,children:e.jsxs(te,{data:i,children:[e.jsx(re,{strokeDasharray:"3 3",className:"stroke-border/30"}),e.jsx(ae,{dataKey:"month",className:"text-xs font-body",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ne,{className:"text-xs font-body",tick:{fill:"hsl(var(--muted-foreground))"},tickFormatter:e=>`$${e}`}),e.jsx(oe,{contentStyle:{backgroundColor:"hsl(var(--background))",border:"1px solid hsl(var(--border))",borderRadius:"8px",backdropFilter:"blur(16px)",fontFamily:"var(--font-body)"},formatter:e=>`$${e.toFixed(2)}`}),e.jsx(le,{wrapperStyle:{fontFamily:"var(--font-body)"}}),e.jsx(de,{type:"monotone",dataKey:"direct",stroke:"hsl(142 76% 36%)",name:"Direct Commissions",strokeWidth:3,dot:{r:4},activeDot:{r:6}}),e.jsx(de,{type:"monotone",dataKey:"overrides",stroke:"hsl(221 83% 53%)",name:"Team Overrides",strokeWidth:3,dot:{r:4},activeDot:{r:6}}),e.jsx(de,{type:"monotone",dataKey:"bonuses",stroke:"hsl(271 91% 65%)",name:"Recruitment Bonuses",strokeWidth:3,dot:{r:4},activeDot:{r:6}})]})})})]})},Se=({referrals:s})=>{const t=(()=>{const e={};return s.forEach(s=>{const t=new Date(s.referral_date).toLocaleDateString("en-US",{year:"numeric",month:"short"});e[t]=(e[t]||0)+1}),Object.entries(e).map(([e,s])=>({month:e,count:s})).sort((e,s)=>new Date(e.month).getTime()-new Date(s.month).getTime())})();return 0===t.length?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsxs(n,{className:"flex items-center gap-2 text-xl font-display font-semibold text-foreground",children:[e.jsx(c,{className:"h-5 w-5 text-primary/60"}),"Referrals by Month"]}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Track your referral activity"})]}),e.jsx(l,{children:e.jsx("div",{className:"flex items-center justify-center h-[300px] text-muted-foreground font-body",children:"No referral data available yet"})})]}):e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsxs(n,{className:"flex items-center gap-2 text-xl font-display font-semibold text-foreground",children:[e.jsx(c,{className:"h-5 w-5 text-primary/60"}),"Referrals by Month"]}),e.jsx(m,{className:"font-body text-muted-foreground",children:"Track your monthly referral performance"})]}),e.jsx(l,{children:e.jsx(se,{width:"100%",height:300,children:e.jsxs(ie,{data:t,children:[e.jsx(re,{strokeDasharray:"3 3",className:"stroke-border/30"}),e.jsx(ae,{dataKey:"month",className:"text-xs font-body",tick:{fill:"hsl(var(--muted-foreground))"}}),e.jsx(ne,{className:"text-xs font-body",tick:{fill:"hsl(var(--muted-foreground))"},allowDecimals:!1}),e.jsx(oe,{contentStyle:{backgroundColor:"hsl(var(--background))",border:"1px solid hsl(var(--border))",borderRadius:"8px",backdropFilter:"blur(16px)",fontFamily:"var(--font-body)"},formatter:e=>[`${e} referrals`,"Count"]}),e.jsx(ce,{dataKey:"count",fill:"hsl(var(--primary))",radius:[8,8,0,0]})]})})})]})},Fe=({title:s,value:t,trend:o,trendValue:d,icon:i})=>e.jsxs(r,{className:"glass-card hover-lift border-border/50 group",children:[e.jsxs(a,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(n,{className:"text-sm font-body font-medium text-muted-foreground",children:s}),e.jsx("span",{className:"transition-transform group-hover:scale-110",children:i})]}),e.jsxs(l,{children:[e.jsx("div",{className:"text-3xl font-display font-bold text-foreground",children:t}),o&&d&&e.jsxs("div",{className:`flex items-center gap-1 text-xs mt-1 font-body ${(()=>{switch(o){case"up":return"text-green-500 dark:text-green-400";case"down":return"text-red-500 dark:text-red-400";default:return"text-muted-foreground"}})()}`,children:[(()=>{if(!o)return null;switch(o){case"up":return e.jsx(xe,{className:"h-4 w-4 text-green-500"});case"down":return e.jsx(me,{className:"h-4 w-4 text-red-500"});default:return e.jsx(y,{className:"h-4 w-4 text-muted-foreground"})}})(),e.jsx("span",{children:d}),e.jsx("span",{className:"text-muted-foreground",children:"vs last month"})]})]})]}),Me=({referrals:s,commissions:t})=>{const r=(()=>{const e=(new Date).getMonth(),r=0===e?11:e-1,a=s.filter(s=>new Date(s.referral_date).getMonth()===e).length,n=s.filter(e=>new Date(e.referral_date).getMonth()===r).length,o=t.filter(e=>"paid"===e.status).length,l=s.length>0?(o/s.length*100).toFixed(1):"0.0",d=t.filter(e=>"paid"===e.status).reduce((e,s)=>e+parseFloat(s.amount),0);return{currentMonthReferrals:a,conversionRate:l,avgDealSize:o>0?(d/o).toFixed(2):"0.00",pendingEarnings:t.filter(e=>"pending"===e.status).reduce((e,s)=>e+parseFloat(s.amount),0),referralTrend:0===n?"neutral":a>n?"up":a<n?"down":"neutral",referralChange:n>0?`${Math.abs((a-n)/n*100).toFixed(0)}%`:a>
10?"100%":"0%"}})();return e.jsxs("div",{className:"grid gap-4 lg:gap-6 md:grid-cols-2 lg:grid-cols-4",children:[e.jsx(Fe,{title:"This Month's Referrals",value:r.currentMonthReferrals,trend:r.referralTrend,trendValue:r.referralChange}),e.jsx(Fe,{title:"Conversion Rate",value:`${r.conversionRate}%`}),e.jsx(Fe,{title:"Average Commission",value:`$${r.avgDealSize}`}),e.jsx(Fe,{title:"Pending Earnings",value:`$${r.pendingEarnings.toFixed(2)}`})]})},$e=({payments:s,isLoading:t})=>t?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsx(a,{children:e.jsx(n,{className:"text-xl font-display font-semibold text-foreground",children:"Payment History"})}),e.jsx(l,{children:e.jsx("div",{className:"h-32 bg-muted/30 animate-pulse rounded-lg shimmer"})})]}):s&&0!==s.length?e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsxs(n,{className:"flex items-center gap-2 text-xl font-display font-semibold text-foreground",children:[e.jsx(d,{className:"h-5 w-5 text-primary/60"}),"Payment History"]}),e.jsx(m,{className:"font-body text-muted-foreground",children:"View your commission payment history"})]}),e.jsx(l,{children:e.jsx("div",{className:"rounded-lg border border-border/50 overflow-hidden",children:e.jsxs(H,{children:[e.jsx(K,{children:e.jsxs(q,{className:"bg-muted/30 hover:bg-muted/40",children:[e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Date"}),e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Batch"}),e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Amount"}),e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Method"}),e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Status"}),e.jsx(U,{className:"font-body font-semibold text-foreground",children:"Paid Date"})]})}),e.jsx(W,{children:s.map(s=>{return e.jsxs(q,{className:"hover:bg-muted/20 transition-colors",children:[e.jsx(I,{children:e.jsxs("div",{className:"flex items-center gap-2 font-body",children:[e.jsx(B,{className:"h-4 w-4 text-muted-foreground"}),Y(new Date(s.created_at),"MMM dd, yyyy")]})}),e.jsx(I,{children:e.jsx("span",{className:"font-mono text-sm font-body",children:s.batch?.batch_number||"N/A"})}),e.jsx(I,{children:e.jsxs("span",{className:"font-display font-bold text-green-600 dark:text-green-400",children:["$",parseFloat(s.amount.toString()).toFixed(2)]})}),e.jsx(I,{children:e.jsx("span",{className:"capitalize font-body",children:s.payment_method})}),e.jsx(I,{children:(t=s.status,e.jsx(u,{className:`${{completed:"bg-green-500/10 text-green-600 dark:text-green-400 border-green-500/20",pending:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 border-yellow-500/20",processing:"bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/20",failed:"bg-red-500/10 text-red-600 dark:text-red-400 border-red-500/20"}[t]||"bg-muted/30"} font-body border`,children:t}))}),e.jsx(I,{children:e.jsx("span",{className:"font-body",children:s.paid_at?Y(new Date(s.paid_at),"MMM dd, yyyy"):e.jsx("span",{className:"text-muted-foreground",children:"-"})})})]},s.id);var t})})]})})})]}):e.jsxs(r,{className:"glass-card border-border/50",children:[e.jsxs(a,{children:[e.jsxs(n,{className:"flex items-center gap-2 text-xl font-display font-semibold text-foreground",children:[e.jsx(d,{className:"h-5 w-5 text-primary/60"}),"Payment History"]}),e.jsx(m,{className:"font-body text-muted-foreground",children:"View your commission payment history"})]}),e.jsx(l,{children:e.jsxs("div",{className:"text-center py-12 space-y-4",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-muted/30 mb-2",children:e.jsx(ue,{className:"h-8 w-8 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-body text-foreground font-medium",children:"No payment history yet"}),e.jsx("p",{className:"text-sm text-muted-foreground font-body max-w-md mx-auto",children:"Your commission payments will appear here once they're processed"})]})]})})]}),Re=({referrals:t,commissions:o,payments:d,agentName:i,agentCode:c})=>{const[x,u]=s.useState(),[h,f]=s.useState(),j=(e,s)=>x&&h?e.filter(e=>{const t=new Date(e[s]);return t>=x&&t<=h}):e;return e.jsxs(r,{children:[e.jsxs(a,{children:[e.jsxs(n,{className:"flex items-center gap-2",children:[e.jsx(N,{className:"h-5 w-5"}),"Export Reports"]}),e.jsx(m,{children:"Download your referral and commission data for accounting purposes"})]}),e.jsxs(l,{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:"Start Date (Optional)"}),e.jsxs(w,{children:[e.jsx(k,{asChild:!0,children:e.jsxs(g,{variant:"outline",className:_("w-full justify-start text-left font-normal",!x&&"text-muted-foreground"),children:[e.jsx(B,{className:"mr-2 h-4 w-4"}),x?Y(x,"PPP"):"Pick a date"]})}),e.jsx(C,{className:"w-auto p-0",align:"start",children:e.jsx(he,{mode:"single",selected:x,onSelect:u,initialFocus:!0})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(v,{children:"End Date (Optional)"}),e.jsxs(w,{children:[e.jsx(k,{asChild:!0,children:e.jsxs(g,{variant:"outline",className:_("w-full justify-start text-left font-normal",!h&&"text-muted-foreground"),children:[e.jsx(B,{className:"mr-2 h-4 w-4"}),h?Y(h,"PPP"):"Pick a date"]})}),e.jsx(C,{className:"w-auto p-0",align:"start",children:e.jsx(he,{mode:"single",selected:h,onSelect:f,initialFocus:!0,disabled:e=>!!x&&e<x})})]})]})]}),x&&h&&e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Exporting data from ",Y(x,"MMM dd, yyyy")," to"," ",Y(h,"MMM dd, yyyy")]}),e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs(g,{variant:"outline",onClick:()=>{const e=j(t,"referral_date");0!==e.length?(fe(e),S.success("Referrals exported to CSV successfully")):S.error("No referrals found in the selected date range")},className:"w-full",disabled:0===t.length,children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Export Referrals (CSV)"]}),e.jsxs(g,{variant:"outline",onClick:()=>{const e=j(o,"due_date");0!==e.length?(ge(e),S.success("Commissions exported to CSV successfully")):S.error("No commissions foun
1d in the selected date range")},className:"w-full",disabled:0===o.length,children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Export Commissions (CSV)"]}),e.jsxs(g,{variant:"outline",onClick:()=>{const e=j(d,"created_at");0!==e.length?(je(e),S.success("Payments exported to CSV successfully")):S.error("No payments found in the selected date range")},className:"w-full",disabled:0===d.length,children:[e.jsx(pe,{className:"mr-2 h-4 w-4"}),"Export Payments (CSV)"]}),e.jsxs(g,{onClick:()=>{const e=j(t,"referral_date"),s=j(o,"due_date"),r=j(d,"created_at");0!==e.length||0!==s.length||0!==r.length?(be({referrals:e,commissions:s,payments:r},{startDate:x,endDate:h,agentName:i,agentCode:c}),S.success("Comprehensive report exported to PDF successfully")):S.error("No data found in the selected date range")},className:"w-full",disabled:0===t.length&&0===o.length&&0===d.length,children:[e.jsx(D,{className:"mr-2 h-4 w-4"}),"Export Full Report (PDF)"]})]})}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-4 p-3 bg-muted rounded-md",children:[e.jsx("p",{className:"font-medium mb-1",children:"Export Tips:"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1",children:[e.jsx("li",{children:"Select date range to filter data (optional)"}),e.jsx("li",{children:"CSV files can be opened in Excel or Google Sheets"}),e.jsx("li",{children:"PDF report includes all data types in one document"}),e.jsx("li",{children:"All exports include only your data"})]})]})]})]})},Te=async e=>{try{const{data:s,error:t}=await F.from("commission_payments").select("\n        *,\n        batch:batch_id(\n          batch_number,\n          payment_date\n        ),\n        commission:commission_id(\n          referral_id,\n          due_date\n        )\n      ").eq("sales_agent_id",e).order("created_at",{ascending:!1});if(t)throw t;return s}catch(s){throw s}},Le=()=>{const o=t(),{user:d}=M(),{loading:i,isAgent:c,agent:m}=O(),[x,u]=s.useState([]),[h,f]=s.useState([]),[b,p]=s.useState([]),[y,N]=s.useState([]),[v,w]=s.useState([]),[k,_]=s.useState([]),[C,F]=s.useState(!0);s.useEffect(()=>{d?i||c||o("/sales-agent-signup"):o("/login")},[d,c,i,o]),s.useEffect(()=>{m?.id&&B()},[m?.id]);const B=async()=>{if(m?.id){F(!0);try{const[e,s,t,r,a,n]=await Promise.all([J(m.id),X(m.id),Q(m.id),Z(m.id),ee(m.id),Te(m.id)]);u(e||[]),f(s||[]),p(t||[]),N(r||[]),w(a||[]),_(n||[])}catch(e){S.error("Failed to load dashboard data")}finally{F(!1)}}};if(i||!m)return e.jsx(z,{title:"Agent Dashboard",children:e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-mansablue mx-auto mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"Loading dashboard..."})]})})});const Y=m.total_earned||0,V=m.total_pending||0,H=h.filter(e=>"paid"===e.status).reduce((e,s)=>e+parseFloat(s.amount),0),K=b.filter(e=>"paid"===e.status).reduce((e,s)=>e+parseFloat(s.override_amount),0),q=y.filter(e=>"paid"===e.status).reduce((e,s)=>e+parseFloat(s.bonus_amount),0);return e.jsxs("div",{className:"min-h-screen bg-black relative overflow-hidden",children:[e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 top-0 h-[480px] opacity-70",style:{background:"radial-gradient(ellipse 70% 50% at 50% 0%, hsl(var(--mansagold) / 0.05), transparent 70%)"}}),e.jsxs(z,{title:"Agent Dashboard",children:[e.jsxs($,{children:[e.jsx("title",{children:"Sales Agent Dashboard | 1325.AI"}),e.jsx("meta",{name:"description",content:"Manage your sales agent account and track your earnings"})]}),e.jsxs("div",{className:"max-w-7xl mx-auto space-y-6 relative z-10",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.jsxs("h1",{className:"font-display text-3xl font-bold tracking-tight text-white",children:["Welcome back, ",m.full_name]}),e.jsx("p",{className:"text-slate-400 mt-1",children:"Here's your sales performance overview"})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>o("/sales-agent-leaderboard"),className:"border-white/15 bg-transparent text-slate-200 hover:bg-white/5 hover:text-white",children:[e.jsx(j,{className:"h-4 w-4 mr-1"}),"Leaderboard"]}),e.jsxs(g,{variant:"outline",size:"sm",onClick:()=>o("/marketing-materials"),className:"border-white/15 bg-transparent text-slate-200 hover:bg-white/5 hover:text-white",children:[e.jsx(D,{className:"h-4 w-4 mr-1"}),"Marketing Materials"]}),e.jsx(R,{}),e.jsxs(r,{className:"w-full sm:w-auto bg-slate-900/40 border-white/10",children:[e.jsx(a,{className:"pb-3",children:e.jsx(n,{className:"text-sm font-medium text-slate-300",children:"Your Referral Code"})}),e.jsxs(l,{className:"space-y-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("code",{className:"text-2xl font-bold text-mansagold bg-black/40 ring-1 ring-mansagold/30 px-3 py-1 rounded",children:m.referral_code})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>{m?.referral_code&&(navigator.clipboard.writeText(m.referral_code),S.success("Referral code copied to clipboard!"))},className:"border-white/15 bg-transparent text-slate-200 hover:bg-white/5 hover:text-white",children:[e.jsx(ye,{className:"h-4 w-4 mr-1"}),"Copy Code"]}),e.jsxs(g,{size:"sm",variant:"outline",onClick:()=>
1{if(m?.referral_code){const e=`${window.location.origin}/business-signup?ref=${m.referral_code}`;navigator.clipboard.writeText(e),S.success("Referral link copied to clipboard!")}},className:"border-white/15 bg-transparent text-slate-200 hover:bg-white/5 hover:text-white",children:[e.jsx(T,{className:"h-4 w-4 mr-1"}),"Copy Link"]})]})]})]})]})]}),e.jsx(Ne,{totalReferrals:m.lifetime_referrals||0,totalEarned:Y,pendingCommissions:V,recruitedAgents:v.length,tier:m.tier||"bronze"}),e.jsxs(L,{defaultValue:"overview",className:"space-y-4",children:[e.jsxs(E,{className:"grid w-full grid-cols-6 bg-slate-900/40 border border-white/10 p-1",children:[e.jsx(P,{value:"overview",className:"text-slate-300 data-[state=active]:bg-mansagold data-[state=active]:text-black data-[state=active]:font-semibold",children:"Overview"}),e.jsx(P,{value:"referrals",className:"text-slate-300 data-[state=active]:bg-mansagold data-[state=active]:text-black data-[state=active]:font-semibold",children:"Referrals"}),e.jsx(P,{value:"team",className:"text-slate-300 data-[state=active]:bg-mansagold data-[state=active]:text-black data-[state=active]:font-semibold",children:"Team"}),e.jsx(P,{value:"commissions",className:"text-slate-300 data-[state=active]:bg-mansagold data-[state=active]:text-black data-[state=active]:font-semibold",children:"Commissions"}),e.jsx(P,{value:"payments",className:"text-slate-300 data-[state=active]:bg-mansagold data-[state=active]:text-black data-[state=active]:font-semibold",children:"Payments"}),e.jsx(P,{value:"export",className:"text-slate-300 data-[state=active]:bg-mansagold data-[state=active]:text-black data-[state=active]:font-semibold",children:"Export"})]}),e.jsxs(A,{value:"overview",className:"space-y-4",children:[e.jsx(Me,{referrals:x,commissions:h}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-4",children:[e.jsx(Ce,{agentId:m.id}),e.jsx("div",{className:"lg:col-span-2",children:e.jsx(we,{directCommissions:H,teamOverrides:K,recruitmentBonuses:q,totalEarnings:Y})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(De,{commissions:h,teamOverrides:b,recruitmentBonuses:y}),e.jsx(Se,{referrals:x})]}),e.jsx(ve,{referrals:x.slice(0,5),isLoading:C}),e.jsx(ke,{recruitedAgents:v,teamOverrides:b,isLoading:C})]}),e.jsx(A,{value:"referrals",children:e.jsx(ve,{referrals:x,isLoading:C})}),e.jsx(A,{value:"team",children:e.jsx(ke,{recruitedAgents:v,teamOverrides:b,isLoading:C})}),e.jsx(A,{value:"commissions",children:e.jsx(_e,{commissions:h,isLoading:C})}),e.jsx(A,{value:"payments",children:e.jsx($e,{payments:k,isLoading:C})}),e.jsx(A,{value:"export",children:e.jsx(Re,{referrals:x,commissions:h,payments:k,agentName:m.full_name,agentCode:m.referral_code})})]})]})]})]})};export{Le 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.