import{j as e}from"./ui-vendor-DUfjpZ4p.js";import{r as S}from"./react-vendor-DlVMRrtE.js";import{h as Je,W as I,s as b,G as Fe,X as wt,E as Ie,q as Se,z as Q,J as qe,x as He,F as ke,e as M,C as L,d as K,w as Ze,Y as De,N as St,Z as Xe,$ as kt,a0 as pe,a1 as Dt,a2 as Tt,a3 as R,a4 as O,a5 as j,a6 as i,a7 as A,a8 as c,a9 as Lt,aa as Kt,ab as Rt,ac as Ot,ad as At,ae as $t,k as Bt,m as Ut}from"./index-BKwmLAPt.js";import{R as Et,T as Pt,A as Te,C as $,X as B,Y as U,a as Le,P as re,b as ae,d as ne,B as H,e as Z}from"./charts-vendor-wgDUSDZK.js";import{C as W,a as Y,b as G}from"./collapsible-C1tJ-4XR.js";import{C as Mt}from"./coins-bWzXYd1B.js";import"./supabase-vendor-Bd7R0Yn5.js";/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ke=Je("Timer",[["line",{x1:"10",x2:"14",y1:"2",y2:"2",key:"14vaq8"}],["line",{x1:"12",x2:"15",y1:"14",y2:"11",key:"17fdiu"}],["circle",{cx:"12",cy:"14",r:"8",key:"1e1u0o"}]]);/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const zt=Je("Zap",[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]]),Wt={light:"",dark:".dark"},Ve=S.createContext(null);function Qe(){const l=S.useContext(Ve);if(!l)throw new Error("useChart must be used within a <ChartContainer />");return l}const v=S.forwardRef(({id:l,className:o,children:t,config:x,...m},r)=>{const g=S.useId(),y=`chart-${l||g.replace(/:/g,"")}`;return e.jsx(Ve.Provider,{value:{config:x},children:e.jsxs("div",{"data-chart":y,ref:r,className:I("flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",o),...m,children:[e.jsx(Yt,{id:y,config:x}),e.jsx(Et,{children:t})]})})});v.displayName="Chart";const Yt=({id:l,config:o})=>{const t=Object.entries(o).filter(([x,m])=>m.theme||m.color);return t.length?e.jsx("style",{dangerouslySetInnerHTML:{__html:Object.entries(Wt).map(([x,m])=>`
${m} [data-chart=${l}] {
${t.map(([r,g])=>{var E;const y=((E=g.theme)==null?void 0:E[x])||g.color;return y?`  --color-${r}: ${y};`:null}).join(`
`)}
}
`).join(`
`)}}):null},N=Pt,C=S.forwardRef(({active:l,payload:o,className:t,indicator:x="dot",hideLabel:m=!1,hideIndicator:r=!1,label:g,labelFormatter:y,labelClassName:E,formatter:w,color:fe,nameKey:be,labelKey:u},ye)=>{const{config:D}=Qe(),q=S.useMemo(()=>{var z;if(m||!(o!=null&&o.length))return null;const[h]=o,p=`${u||h.dataKey||h.name||"value"}`,d=$e(D,h,p),a=!u&&typeof g=="string"?((z=D[g])==null?void 0:z.label)||g:d==null?void 0:d.label;return y?e.jsx("div",{className:I("font-medium",E),children:y(a,o)}):a?e.jsx("div",{className:I("font-medium",E),children:a}):null},[g,y,o,m,E,D,u]);if(!l||!(o!=null&&o.length))return null;const te=o.length===1&&x!=="dot";return e.jsxs("div",{ref:ye,className:I("grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",t),children:[te?null:q,e.jsx("div",{className:"grid gap-1.5",children:o.map((h,p)=>{const d=`${be||h.name||h.dataKey||"value"}`,a=$e(D,h,d),z=fe||h.payload.fill||h.color;return e.jsx("div",{className:I("flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",x==="dot"&&"items-center"),children:w&&(h==null?void 0:h.value)!==void 0&&h.name?w(h.value,h.name,h,p,h.payload):e.jsxs(e.Fragment,{children:[a!=null&&a.icon?e.jsx(a.icon,{}):!r&&e.jsx("div",{className:I("shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",{"h-2.5 w-2.5":x==="dot","w-1":x==="line","w-0 border-[1.5px] border-dashed bg-transparent":x==="dashed","my-0.5":te&&x==="dashed"}),style:{"--color-bg":z,"--color-border":z}}),e.jsxs("div",{className:I("flex flex-1 justify-between leading-none",te?"items-end":"items-center"),children:[e.jsxs("div",{className:"grid gap-1.5",children:[te?q:null,e.jsx("span",{className:"text-muted-foreground",children:(a==null?void 0:a.label)||h.name})]}),h.value&&e.jsx("span",{className:"font-mono font-medium tabular-nums text-foreground",children:h.value.toLocaleString()})]})]})},h.dataKey)})})]})});C.displayName="ChartTooltip";const Gt=S.forwardRef(({className:l,hideIcon:o=!1,payload:t,verticalAlign:x="bottom",nameKey:m},r)=>{const{config:g}=Qe();return t!=null&&t.length?e.jsx("div",{ref:r,className:I("flex items-center justify-center gap-4",x==="top"?"pb-3":"pt-3",l),children:t.map(y=>{const E=`${m||y.dataKey||"value"}`,w=$e(g,y,E);return e.jsxs("div",{className:I("flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"),children:[w!=null&&w.icon&&!o?e.jsx(w.icon,{}):e.jsx("div",{className:"h-2 w-2 shrink-0 rounded-[2px]",style:{backgroundColor:y.color}}),w==null?void 0:w.label]},y.value)})}):null});Gt.displayName="ChartLegend";function $e(l,o,t){if(typeof o!="object"||o===null)return;const x="payload"in o&&typeof o.payload=="object"&&o.payload!==null?o.payload:void 0;let m=t;return t in o&&typeof o[t]=="string"?m=o[t]:x&&t in x&&typeof x[t]=="string"&&(m=x[t]),m in l?l[m]:l[t]}const T=["hsl(var(--primary))","hsl(var(--accent))","hsl(142, 76%, 36%)","hsl(38, 92%, 50%)","hsl(0, 84%, 60%)","hsl(262, 83%, 58%)","hsl(200, 80%, 50%)","hsl(330, 70%, 50%)"],Re=l=>{const o={};return l.forEach(t=>{const x=new Date(t.created_at),m=`${x.getFullYear()}-${String(x.getMonth()+1).padStart(2,"0")}`;o[m]=(o[m]||0)+1}),Object.entries(o).sort(([t],[x])=>t.localeCompare(x)).slice(-12).map(([t,x])=>({month:t,count:x}))},P=(l,o)=>{const t={};return l.forEach(x=>{const m=x[o]||"Unknown";t[m]=(t[m]||0)+1}),Object.entries(t).map(([x,m])=>({name:x,value:m}))},Oe=1e3,k=async l=>{const o=[];for(let t=0;;t+=Oe){const{data:x,error:m,count:r}=await l.range(t,t+Oe-1);if(m)throw m;const g=x||[];if(o.push(...g),g.length<Oe||typeof r=="number"&&o.length>=r)break}return o},F=({icon:l,title:o,color:t,dotColor:x,isOpen:m})=>e.jsxs("div",{className:"flex items-center justify-between w-full py-3.5 px-5 rounded-xl bg-card/80 backdrop-blur-sm border border-border/60 shadow-sm hover:shadow-md transition-all duration-300 cursor-pointer group",style:{borderLeftWidth:"4px",borderLeftColor:x},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-lg p-1.5",style:{backgroundColor:`${x}15`},children:e.jsx(l,{className:`h-5 w-5 ${t}`})}),e.jsx("h2",{className:"text-lg font-heading font-bold text-foreground tracking-tight",children:o})]}),e.jsx(Tt,{className:`h-5 w-5 text-muted-foreground transition-transform duration-300 ${m?"rotate-180":""} group-hover:text-foreground`})]}),ee=l=>l?new Date(l).toLocaleDateString():"—",Ae=l=>l!=null?`$${l.toLocaleString()}`:"—",Ft=({activeKey:l,onClose:o,rawData:t})=>{if(!l)return null;const m={totalUsers:{title:"All Users",description:`${t.profiles.length} total registered users`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Name"}),e.jsx(i,{children:"Email"}),e.jsx(i,{children:"Type"}),e.jsx(i,{children:"Joined"})]})}),e.jsx(A,{children:t.profiles.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium",children:r.full_name||"—"}),e.jsx(c,{className:"text-muted-foreground text-xs",children:r.email||"—"}),e.jsx(c,{children:e.jsx(M,{variant:"outline",className:"text-xs",children:r.account_type})}),e.jsx(c,{className:"text-xs text-muted-foreground",children:ee(r.created_at)})]},r.id))})]})},activeUsers:{title:"Active Users (Last 24h)",description:`${t.activeProfiles.length} users active in the last 24 hours`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Name"}),e.jsx(i,{children:"Email"}),e.jsx(i,{children:"Last Seen"})]})}),e.jsx(A,{children:t.activeProfiles.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium",children:r.full_name||"—"}),e.jsx(c,{className:"text-muted-foreground text-xs",children:r.email||"—"}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.last_seen_at?new Date(r.last_seen_at).toLocaleString():"—"})]},r.id))})]})},onlineUsers:{title:"Currently Online",description:`${t.onlineProfiles.length} users online now`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Name"}),e.jsx(i,{children:"Email"}),e.jsx(i,{children:"Last Seen"})]})}),e.jsx(A,{children:t.onlineProfiles.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium",children:r.full_name||"—"}),e.jsx(c,{className:"text-muted-foreground text-xs",children:r.email||"—"}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.last_seen_at?new Date(r.last_seen_at).toLocaleString():"—"})]},r.id))})]})},companies:{title:"All Companies",description:`${t.companies.length} companies in database`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Company"}),e.jsx(i,{children:"Country"}),e.jsx(i,{children:"Industry"}),e.jsx(i,{children:"Status"})]})}),e.jsx(A,{children:t.companies.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium",children:r.company_name}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.country||"—"}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.industry||"—"}),e.jsx(c,{children:e.jsx(M,{variant:"outline",className:"text-xs",children:r.business_status||"—"})})]},r.id))})]})},debtors:{title:"Debtor Profiles",description:`${t.debtors.length} debtor profiles`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Company"}),e.jsx(i,{children:"Country"}),e.jsx(i,{children:"Debt Owed"}),e.jsx(i,{children:"Status"})]})}),e.jsx(A,{children:t.debtors.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium",children:r.debtor_company_name}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.country_of_operation||"—"}),e.jsx(c,{className:"text-xs font-medium",children:Ae(r.debt_owed_usd)}),e.jsx(c,{children:e.jsx(M,{variant:"outline",className:"text-xs",children:r.business_status||"—"})})]},r.id))})]})},kycCases:{title:"KYC Cases",description:`${t.cases.length} total KYC cases`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Title"}),e.jsx(i,{children:"Type"}),e.jsx(i,{children:"Status"}),e.jsx(i,{children:"Created"})]})}),e.jsx(A,{children:t.cases.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium",children:r.title}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.case_type}),e.jsx(c,{children:e.jsx(M,{variant:r.status==="Completed"?"default":"secondary",className:"text-xs",children:r.status})}),e.jsx(c,{className:"text-xs text-muted-foreground",children:ee(r.created_at)})]},r.id))})]})},recoveryCases:{title:"Recovery Cases",description:`${t.recoveryCases.length} total recovery cases`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Case #"}),e.jsx(i,{children:"Debtor"}),e.jsx(i,{children:"Status"}),e.jsx(i,{children:"Placement"}),e.jsx(i,{children:"Recovered"})]})}),e.jsx(A,{children:t.recoveryCases.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium",children:r.case_number}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.debtor_company}),e.jsx(c,{children:e.jsx(M,{variant:r.status==="Closed"?"secondary":"default",className:"text-xs",children:r.status})}),e.jsx(c,{className:"text-xs",children:Ae(r.placement_amount)}),e.jsx(c,{className:"text-xs text-green-600 font-medium",children:Ae(r.amount_paid)})]},r.id))})]})},starSteel:{title:"Star Steel Assignments",description:`${t.kycAssignments.length} total assignments`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Ref"}),e.jsx(i,{children:"Company"}),e.jsx(i,{children:"Type"}),e.jsx(i,{children:"Status"}),e.jsx(i,{children:"Created"})]})}),e.jsx(A,{children:t.kycAssignments.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium text-xs",children:r.assignment_ref}),e.jsx(c,{className:"text-xs",children:r.company_name}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.request_type}),e.jsx(c,{children:e.jsx(M,{variant:"outline",className:"text-xs",children:r.status})}),e.jsx(c,{className:"text-xs text-muted-foreground",children:ee(r.created_at)})]},r.id))})]})},overdueKYC:{title:"Overdue KYC Cases",description:`${t.overdueKYCList.length} cases pending > 30 days`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Title"}),e.jsx(i,{children:"Type"}),e.jsx(i,{children:"Status"}),e.jsx(i,{children:"Created"})]})}),e.jsx(A,{children:t.overdueKYCList.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium",children:r.title}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.case_type}),e.jsx(c,{children:e.jsx(M,{variant:"destructive",className:"text-xs",children:r.status})}),e.jsx(c,{className:"text-xs text-muted-foreground",children:ee(r.created_at)})]},r.id))})]})},overdueRecovery:{title:"Overdue Recovery Cases",description:`${t.overdueRecoveryList.length} cases active/pending > 30 days`,content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Case #"}),e.jsx(i,{children:"Debtor"}),e.jsx(i,{children:"Status"}),e.jsx(i,{children:"Created"})]})}),e.jsx(A,{children:t.overdueRecoveryList.map(r=>e.jsxs(j,{children:[e.jsx(c,{className:"font-medium",children:r.case_number}),e.jsx(c,{className:"text-xs text-muted-foreground",children:r.debtor_company}),e.jsx(c,{children:e.jsx(M,{variant:"destructive",className:"text-xs",children:r.status})}),e.jsx(c,{className:"text-xs text-muted-foreground",children:ee(r.created_at)})]},r.id))})]})},avgTurnaround:{title:"Completed/Closed Cases — Turnaround",description:"Showing turnaround time for completed & closed cases",content:e.jsxs(R,{children:[e.jsx(O,{children:e.jsxs(j,{children:[e.jsx(i,{children:"Case"}),e.jsx(i,{children:"Status"}),e.jsx(i,{children:"Created"}),e.jsx(i,{children:"Closed"}),e.jsx(i,{children:"Days"})]})}),e.jsx(A,{children:[...t.cases,...t.recoveryCases].filter(r=>{var g,y;return((g=r.status)==null?void 0:g.toLowerCase())==="completed"||((y=r.status)==null?void 0:y.toLowerCase())==="closed"}).map(r=>{const g=Math.round((new Date(r.updated_at).getTime()-new Date(r.created_at).getTime())/864e5);return e.jsxs(j,{children:[e.jsx(c,{className:"font-medium text-xs",children:r.title||r.case_number||"—"}),e.jsx(c,{children:e.jsx(M,{variant:"secondary",className:"text-xs",children:r.status})}),e.jsx(c,{className:"text-xs text-muted-foreground",children:ee(r.created_at)}),e.jsx(c,{className:"text-xs text-muted-foreground",children:ee(r.updated_at)}),e.jsxs(c,{className:"text-xs font-bold",children:[g,"d"]})]},r.id)})})]})}}[l];return m?e.jsx(Lt,{open:!!l,onOpenChange:()=>o(),children:e.jsxs(Kt,{className:"max-w-3xl max-h-[80vh]",children:[e.jsxs(Rt,{children:[e.jsx(Ot,{className:"font-heading",children:m.title}),e.jsx(At,{children:m.description})]}),e.jsx($t,{className:"max-h-[60vh]",children:m.content})]})}):null},_=({title:l,dotColor:o,children:t,className:x=""})=>e.jsxs(L,{className:`relative overflow-hidden border-border/60 bg-card/90 backdrop-blur-sm shadow-sm hover:shadow-lg transition-all duration-300 ${x}`,children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-[3px]",style:{background:`linear-gradient(90deg, ${o||"hsl(var(--accent))"}, ${o||"hsl(var(--accent))"}40)`}}),e.jsx(Bt,{className:"pb-2",children:e.jsxs(Ut,{className:"text-base font-heading flex items-center gap-2",children:[e.jsx("span",{className:"h-2 w-2 rounded-full shrink-0",style:{backgroundColor:o||"hsl(var(--accent))"}}),l]})}),e.jsx(K,{children:t})]}),es=()=>{const[l,o]=S.useState(null),[t,x]=S.useState(null),[m,r]=S.useState({profiles:[],activeProfiles:[],onlineProfiles:[],companies:[],debtors:[],cases:[],recoveryCases:[],kycAssignments:[],overdueKYCList:[],overdueRecoveryList:[]}),[g,y]=S.useState(!0),[E,w]=S.useState(null),[fe,be]=S.useState(null),[u,ye]=S.useState({users:!0,kyc:!0,recovery:!0,starSteel:!0,operational:!0,clients:!0,financial:!0,governance:!0,watchlist:!0}),D=d=>ye(a=>({...a,[d]:!a[d]})),q=S.useCallback(async(d=!1)=>{d&&y(!0);try{const a=new Date,z=new Date(a.getTime()-24*60*60*1e3).toISOString(),ve=new Date(a.getTime()-5*60*1e3).toISOString(),le=new Date(a.getTime()-30*24*60*60*1e3).toISOString(),[se,Be,Ue,Ee,Ce,X,Ne,oe,et,tt,st,rt,at,nt,lt,ot,it,me,ie,he]=await Promise.all([k(b.from("profiles").select("id, created_at, account_type, full_name, last_seen_at, email",{count:"exact"})),k(b.from("profiles").select("id, full_name, email, last_seen_at",{count:"exact"}).gte("last_seen_at",z)),k(b.from("profiles").select("id, full_name, email, last_seen_at",{count:"exact"}).gte("last_seen_at",ve)),k(b.from("companies").select("id, company_name, country, industry, business_status",{count:"exact"})),k(b.from("debtors").select("id, debt_owed_usd, paid_amount, country_of_operation, debtor_company_name, outstanding_debts_usd, business_status",{count:"exact"})),k(b.from("cases").select("id, status, case_type, created_at, updated_at, client_id, title",{count:"exact"})),k(b.from("recovery_cases").select("id, status, country, placement_amount, amount_paid, created_at, updated_at, client_id, client_name, case_number, debtor_company",{count:"exact"})),k(b.from("kyc_assignments").select("id, status, created_at, updated_at, request_type, submitted_by, assignment_ref, company_name",{count:"exact"})),k(b.from("user_roles").select("role",{count:"exact"})),k(b.from("trade_check_submissions").select("id, created_at, status",{count:"exact"})),b.from("reports").select("id",{count:"exact",head:!0}),k(b.from("recovery_payments").select("amount_paid, currency, payment_date, created_at",{count:"exact"})),k(b.from("company_correction_requests").select("id, status",{count:"exact"})),k(b.from("company_profile_claims").select("id, status",{count:"exact"})),b.from("credit_consent_records").select("id",{count:"exact",head:!0}),b.from("company_watchlist").select("id",{count:"exact",head:!0}),b.from("debtor_watchlist").select("id",{count:"exact",head:!0}),k(b.from("email_send_log").select("id, status, created_at",{count:"exact"})),k(b.from("debt_cases").select("id, case_ref, debtor_name, debtor_country, total_amount, min_settlement, outstanding_balance, currency, status, source_module, created_at, updated_at, client_id, submitted_by, client_name",{count:"exact"}).eq("source_module","recovery")),fetch("https://open.er-api.com/v6/latest/USD").then(s=>s.json()).catch(()=>null)]);let _e={USD:1,GHS:.065,EUR:1.08,GBP:1.27,CNY:.14};if(he!=null&&he.rates){_e={USD:1};for(const[s,n]of Object.entries(he.rates))_e[s]=1/n}const J=(s,n)=>s*(_e[(n||"USD").toUpperCase()]??1),ue=s=>{if(s.min_settlement!=null)return Math.max(0,Number(s.min_settlement)||0);const n=Number(s.total_amount)||0,f=s.outstanding_balance==null?n:Number(s.outstanding_balance)||0;return Math.max(0,n-f)},ct=ie.map(s=>{const n=s.currency||"USD";return{...s,id:`debt-${s.id}`,case_number:s.case_ref,debtor_company:s.debtor_name,country:s.debtor_country||"Unknown",placement_amount:J(Number(s.total_amount)||0,n),amount_paid:J(ue(s),n),client_id:s.client_id||s.submitted_by}}),V=[...Ne,...ct],Pe=X.filter(s=>{var n;return((n=s.status)==null?void 0:n.toLowerCase())==="pending"&&new Date(s.created_at)<new Date(le)}),Me=V.filter(s=>{var n,f;return(((n=s.status)==null?void 0:n.toLowerCase())==="pending"||((f=s.status)==null?void 0:f.toLowerCase())==="active")&&new Date(s.created_at)<new Date(le)});r({profiles:se,activeProfiles:Be,onlineProfiles:Ue,companies:Ee,debtors:Ce,cases:X,recoveryCases:V,kycAssignments:oe,overdueKYCList:Pe,overdueRecoveryList:Me});const dt=Ne.reduce((s,n)=>s+(Number(n.placement_amount)||0),0),xt=Ne.reduce((s,n)=>s+(Number(n.amount_paid)||0),0),mt=ie.reduce((s,n)=>s+J(Number(n.total_amount)||0,n.currency||"USD"),0),ht=ie.reduce((s,n)=>s+J(ue(n),n.currency||"USD"),0),ut=dt+mt,jt=xt+ht,ce={};rt.forEach(s=>{const n=new Date(s.payment_date||s.created_at),f=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}`;ce[f]=(ce[f]||0)+J(Number(s.amount_paid||0),s.currency||"USD")}),ie.forEach(s=>{const n=ue(s);if(n<=0)return;const f=new Date(s.updated_at||s.created_at),ge=`${f.getFullYear()}-${String(f.getMonth()+1).padStart(2,"0")}`;ce[ge]=(ce[ge]||0)+J(n,s.currency||"USD")});const gt=P(oe,"request_type"),pt=Re(oe),we=[...X,...V].filter(s=>{var n,f;return((n=s.status)==null?void 0:n.toLowerCase())==="completed"||((f=s.status)==null?void 0:f.toLowerCase())==="closed"});let ze=0;we.forEach(s=>{const n=new Date(s.created_at).getTime(),f=new Date(s.updated_at).getTime();ze+=(f-n)/(1e3*60*60*24)});const ft=we.length>0?Math.round(ze/we.length):0,de={};X.forEach(s=>{de[s.client_id]=(de[s.client_id]||0)+1}),V.forEach(s=>{s.client_id&&(de[s.client_id]=(de[s.client_id]||0)+1)});const We={};se.forEach(s=>{We[s.id]=s.full_name||"Unknown"});const bt=Object.entries(de).sort(([,s],[,n])=>n-s).slice(0,10).map(([s,n])=>({name:We[s]||s.slice(0,8),cases:n})),je={},Ye=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];se.forEach(s=>{if(s.last_seen_at){const n=new Date(s.last_seen_at),f=Ye[n.getDay()];je[f]||(je[f]=new Set),je[f].add(s.id)}});const yt=Ye.map(s=>{var n;return{day:s,count:((n=je[s])==null?void 0:n.size)||0}}),xe={};Ce.forEach(s=>{const n=s.country_of_operation||"Unknown";xe[n]=(xe[n]||0)+(Number(s.outstanding_debts_usd)||0)}),ie.forEach(s=>{const n=s.debtor_country||"Unknown",f=Number(s.total_amount)||0,ge=ue(s),_t=s.outstanding_balance==null?Math.max(0,f-ge):Number(s.outstanding_balance)||0;xe[n]=(xe[n]||0)+J(Math.max(0,_t),s.currency||"USD")});const vt=Object.entries(xe).filter(([,s])=>s>0).sort(([,s],[,n])=>n-s).slice(0,8).map(([s,n])=>({name:s,amount:n})),Ge=me.filter(s=>s.status==="sent").length,Ct=me.filter(s=>s.status==="failed"||s.status==="error").length,Nt=me.length>0?Math.round(Ge/me.length*100):100;o({totalUsers:se.length,activeUsers:Be.length,onlineUsers:Ue.length,totalCompanies:Ee.length,totalDebtors:Ce.length,totalKYCCases:X.length,totalRecoveryCases:V.length,totalStarSteelAssignments:oe.length}),x({userGrowth:Re(se),roleDistribution:P(et,"role"),accountTypes:P(se,"account_type"),kycByStatus:P(X,"status"),kycByType:P(X,"case_type"),tradeCheckTrend:Re(tt),recoveryByStatus:P(V,"status"),recoveryByCountry:P(V,"country").sort((s,n)=>n.value-s.value).slice(0,8),recoveryPaymentTrend:Object.entries(ce).sort(([s],[n])=>s.localeCompare(n)).slice(-12).map(([s,n])=>({month:s,amount:n})),starSteelByStatus:P(oe,"status"),starSteelByType:gt,starSteelMonthly:pt,correctionsByStatus:P(at,"status"),claimsByStatus:P(nt,"status"),totalDebtPlaced:ut,totalRecovered:jt,reportsCount:st.count||0,creditConsentCount:lt.count||0,companyWatchlistCount:ot.count||0,debtorWatchlistCount:it.count||0,avgTurnaroundDays:ft,overdueKYCCases:Pe.length,overdueRecoveryCases:Me.length,topClients:bt,loginFrequency:yt,outstandingDebtByCountry:vt,emailSuccessRate:Nt,totalEmailsSent:Ge,totalEmailsFailed:Ct}),be(new Date)}catch(a){console.error("Analytics fetch error:",a)}finally{y(!1)}},[]);if(S.useEffect(()=>{q(!0);let d=null;const a=()=>{d&&clearTimeout(d),d=setTimeout(()=>q(!1),750)},z=b.channel("super-admin-analytics-live").on("postgres_changes",{event:"*",schema:"public",table:"profiles"},a).on("postgres_changes",{event:"*",schema:"public",table:"companies"},a).on("postgres_changes",{event:"*",schema:"public",table:"debtors"},a).on("postgres_changes",{event:"*",schema:"public",table:"cases"},a).on("postgres_changes",{event:"*",schema:"public",table:"recovery_cases"},a).on("postgres_changes",{event:"*",schema:"public",table:"debt_cases"},a).on("postgres_changes",{event:"*",schema:"public",table:"recovery_payments"},a).on("postgres_changes",{event:"*",schema:"public",table:"kyc_assignments"},a).on("postgres_changes",{event:"*",schema:"public",table:"user_roles"},a).on("postgres_changes",{event:"*",schema:"public",table:"trade_check_submissions"},a).on("postgres_changes",{event:"*",schema:"public",table:"reports"},a).on("postgres_changes",{event:"*",schema:"public",table:"company_correction_requests"},a).on("postgres_changes",{event:"*",schema:"public",table:"company_profile_claims"},a).on("postgres_changes",{event:"*",schema:"public",table:"credit_consent_records"},a).on("postgres_changes",{event:"*",schema:"public",table:"company_watchlist"},a).on("postgres_changes",{event:"*",schema:"public",table:"debtor_watchlist"},a).on("postgres_changes",{event:"*",schema:"public",table:"email_send_log"},a).subscribe(),ve=setInterval(()=>q(!1),6e4),le=()=>{document.hidden||q(!1)};return document.addEventListener("visibilitychange",le),()=>{d&&clearTimeout(d),clearInterval(ve),document.removeEventListener("visibilitychange",le),b.removeChannel(z)}},[q]),g)return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("div",{className:"h-9 w-64 rounded-lg bg-gradient-to-r from-muted to-muted/50 animate-pulse"}),e.jsx("div",{className:"h-4 w-96 mt-2 rounded bg-muted/60 animate-pulse"})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:Array.from({length:8}).map((d,a)=>e.jsx("div",{className:"h-28 rounded-xl bg-gradient-to-br from-muted/80 to-muted/30 animate-pulse border border-border/30"},a))}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:Array.from({length:4}).map((d,a)=>e.jsx("div",{className:"h-72 rounded-xl bg-gradient-to-br from-muted/80 to-muted/30 animate-pulse border border-border/30"},a))})]});const te=t&&t.totalDebtPlaced>0?(t.totalRecovered/t.totalDebtPlaced*100).toFixed(1):"0",h=[{label:"Total Users",value:(l==null?void 0:l.totalUsers)||0,icon:Fe,gradient:"from-primary/8 to-primary/3",iconBg:"bg-primary/15",borderColor:"hsl(var(--primary))",drillKey:"totalUsers"},{label:"Active (24h)",value:(l==null?void 0:l.activeUsers)||0,icon:wt,gradient:"from-emerald-500/8 to-emerald-500/3",iconBg:"bg-emerald-500/15",borderColor:"hsl(142, 76%, 36%)",drillKey:"activeUsers"},{label:"Online Now",value:(l==null?void 0:l.onlineUsers)||0,icon:Ie,gradient:"from-green-500/8 to-green-500/3",iconBg:"bg-green-500/15",borderColor:"hsl(142, 76%, 42%)",drillKey:"onlineUsers"},{label:"Companies",value:(l==null?void 0:l.totalCompanies)||0,icon:Se,gradient:"from-blue-500/8 to-blue-500/3",iconBg:"bg-blue-500/15",borderColor:"hsl(200, 80%, 50%)",drillKey:"companies"},{label:"Debtor Profiles",value:(l==null?void 0:l.totalDebtors)||0,icon:Q,gradient:"from-amber-500/8 to-amber-500/3",iconBg:"bg-amber-500/15",borderColor:"hsl(38, 92%, 50%)",drillKey:"debtors"},{label:"KYC Cases",value:(l==null?void 0:l.totalKYCCases)||0,icon:qe,gradient:"from-purple-500/8 to-purple-500/3",iconBg:"bg-purple-500/15",borderColor:"hsl(262, 83%, 58%)",drillKey:"kycCases"},{label:"Recovery Cases",value:(l==null?void 0:l.totalRecoveryCases)||0,icon:He,gradient:"from-red-500/8 to-red-500/3",iconBg:"bg-red-500/15",borderColor:"hsl(0, 84%, 60%)",drillKey:"recoveryCases"},{label:"Star Steel KYC",value:(l==null?void 0:l.totalStarSteelAssignments)||0,icon:ke,gradient:"from-indigo-500/8 to-indigo-500/3",iconBg:"bg-indigo-500/15",borderColor:"hsl(234, 89%, 58%)",drillKey:"starSteel"}],p={count:{label:"Count",color:"hsl(var(--primary))"},amount:{label:"Amount (USD)",color:"hsl(var(--primary))"},value:{label:"Value",color:"hsl(var(--primary))"},cases:{label:"Cases",color:"hsl(var(--primary))"}};return e.jsxs("div",{className:"space-y-7",children:[e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-heading font-extrabold text-gradient-gold",children:"System Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1.5",children:"Real-time platform insights — click any card to drill down."})]}),e.jsxs(M,{variant:"outline",className:"text-xs font-normal gap-1.5 py-1 px-3 border-border/60",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-green-500 animate-pulse"}),"Updated ",(fe||new Date).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:h.map(d=>e.jsxs(L,{className:`relative overflow-hidden bg-gradient-to-br ${d.gradient} backdrop-blur-sm border-border/40 cursor-pointer hover:shadow-xl hover:scale-[1.03] transition-all duration-300 group`,style:{borderLeftWidth:"3px",borderLeftColor:d.borderColor},onClick:()=>w(d.drillKey),children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-tr from-transparent via-white/5 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"}),e.jsxs(K,{className:"p-4 flex items-center gap-3 relative",children:[e.jsx("div",{className:`rounded-xl p-2.5 ${d.iconBg} shadow-sm`,children:e.jsx(d.icon,{className:"h-6 w-6 shrink-0",style:{color:d.borderColor}})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-heading font-bold text-foreground",children:d.value.toLocaleString()}),e.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:d.label})]})]})]},d.label))}),e.jsx(Ft,{activeKey:E,onClose:()=>w(null),rawData:m}),e.jsxs(W,{open:u.users,onOpenChange:()=>D("users"),children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{children:e.jsx(F,{icon:Fe,title:"User Analytics",color:"text-primary",dotColor:"hsl(var(--primary))",isOpen:u.users})})}),e.jsx(G,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mt-4",children:[e.jsx(_,{title:"User Growth (Monthly)",dotColor:"hsl(var(--primary))",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(Te,{data:(t==null?void 0:t.userGrowth)||[],children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"userGrowthGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"hsl(var(--primary))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(var(--primary))",stopOpacity:0})]})}),e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{dataKey:"month",tick:{fontSize:11}}),e.jsx(U,{tick:{fontSize:11}}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Le,{type:"monotone",dataKey:"count",stroke:"hsl(var(--primary))",strokeWidth:2.5,fill:"url(#userGrowthGrad)",dot:{r:3,fill:"hsl(var(--primary))"}})]})})}),e.jsx(_,{title:"Role Distribution",dotColor:"hsl(var(--accent))",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(re,{children:[e.jsx(ae,{data:(t==null?void 0:t.roleDistribution)||[],dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:80,label:({name:d,value:a})=>`${d}: ${a}`,children:t==null?void 0:t.roleDistribution.map((d,a)=>e.jsx(ne,{fill:T[a%T.length]},a))}),e.jsx(N,{content:e.jsx(C,{})})]})})}),e.jsx(_,{title:"Account Types",dotColor:"hsl(142, 76%, 36%)",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(re,{children:[e.jsx(ae,{data:(t==null?void 0:t.accountTypes)||[],dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:80,label:({name:d,value:a})=>`${d}: ${a}`,children:t==null?void 0:t.accountTypes.map((d,a)=>e.jsx(ne,{fill:T[a%T.length]},a))}),e.jsx(N,{content:e.jsx(C,{})})]})})})]})})]}),e.jsxs(W,{open:u.kyc,onOpenChange:()=>D("kyc"),children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{children:e.jsx(F,{icon:qe,title:"KYC Module",color:"text-purple-600",dotColor:"hsl(262, 83%, 58%)",isOpen:u.kyc})})}),e.jsx(G,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mt-4",children:[e.jsx(_,{title:"Cases by Status",dotColor:"hsl(262, 83%, 58%)",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(H,{data:(t==null?void 0:t.kycByStatus)||[],children:[e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{dataKey:"name",tick:{fontSize:11}}),e.jsx(U,{tick:{fontSize:11}}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Z,{dataKey:"value",fill:"hsl(262, 83%, 58%)",radius:[6,6,0,0]})]})})}),e.jsx(_,{title:"Cases by Type",dotColor:"hsl(var(--accent))",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(H,{data:(t==null?void 0:t.kycByType)||[],layout:"vertical",children:[e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{type:"number",tick:{fontSize:11}}),e.jsx(U,{dataKey:"name",type:"category",tick:{fontSize:11},width:100}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Z,{dataKey:"value",fill:"hsl(var(--accent))",radius:[0,6,6,0]})]})})}),e.jsx(_,{title:"Trade Check Submissions (Monthly)",dotColor:"hsl(var(--accent))",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(Te,{data:(t==null?void 0:t.tradeCheckTrend)||[],children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"tradeCheckGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"hsl(var(--accent))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(var(--accent))",stopOpacity:0})]})}),e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{dataKey:"month",tick:{fontSize:11}}),e.jsx(U,{tick:{fontSize:11}}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Le,{type:"monotone",dataKey:"count",stroke:"hsl(var(--accent))",strokeWidth:2.5,fill:"url(#tradeCheckGrad)",dot:{r:3,fill:"hsl(var(--accent))"}})]})})}),e.jsxs(L,{className:"relative overflow-hidden flex items-center justify-center border-border/60 bg-gradient-to-br from-primary/10 to-primary/3 backdrop-blur-sm",children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-[3px]",style:{background:"linear-gradient(90deg, hsl(var(--primary)), hsl(var(--primary) / 0.4))"}}),e.jsx("div",{className:"absolute bottom-2 right-2 opacity-[0.06]",children:e.jsx(ke,{className:"h-24 w-24"})}),e.jsxs(K,{className:"text-center py-8 relative",children:[e.jsx("div",{className:"rounded-xl p-3 bg-primary/15 mx-auto mb-3 w-fit",children:e.jsx(ke,{className:"h-8 w-8 text-primary"})}),e.jsx("p",{className:"text-3xl font-heading font-bold text-foreground",children:(t==null?void 0:t.reportsCount)||0}),e.jsx("p",{className:"text-sm text-muted-foreground font-medium",children:"Total Reports Uploaded"})]})]})]})})]}),e.jsxs(W,{open:u.recovery,onOpenChange:()=>D("recovery"),children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{children:e.jsx(F,{icon:He,title:"Debt Recovery",color:"text-red-600",dotColor:"hsl(0, 84%, 60%)",isOpen:u.recovery})})}),e.jsxs(G,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mt-4 mb-6",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-xl p-6 text-center shadow-lg",style:{background:"linear-gradient(135deg, hsl(var(--primary)), hsl(213, 68%, 22%))"},children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.08]",children:e.jsx(Ze,{className:"h-20 w-20 text-white"})}),e.jsx("p",{className:"text-xs text-white/70 uppercase tracking-wider mb-1 font-medium",children:"Total Debt Placed"}),e.jsxs("p",{className:"text-2xl font-heading font-bold text-white",children:["$",((t==null?void 0:t.totalDebtPlaced)||0).toLocaleString()]})]}),e.jsxs("div",{className:"relative overflow-hidden rounded-xl p-6 text-center shadow-lg",style:{background:"linear-gradient(135deg, hsl(346, 70%, 30%), hsl(346, 70%, 18%))"},children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.08]",children:e.jsx(Mt,{className:"h-20 w-20 text-white"})}),e.jsx("p",{className:"text-xs text-white/70 uppercase tracking-wider mb-1 font-medium",children:"Total Outstanding"}),e.jsxs("p",{className:"text-2xl font-heading font-bold text-white",children:["$",Math.max(0,((t==null?void 0:t.totalDebtPlaced)||0)-((t==null?void 0:t.totalRecovered)||0)).toLocaleString()]})]}),e.jsxs("div",{className:"relative overflow-hidden rounded-xl p-6 text-center shadow-lg",style:{background:"linear-gradient(135deg, hsl(142, 76%, 36%), hsl(142, 76%, 28%))"},children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.08]",children:e.jsx(De,{className:"h-20 w-20 text-white"})}),e.jsx("p",{className:"text-xs text-white/70 uppercase tracking-wider mb-1 font-medium",children:"Total Recovered"}),e.jsxs("p",{className:"text-2xl font-heading font-bold text-white",children:["$",((t==null?void 0:t.totalRecovered)||0).toLocaleString()]})]}),e.jsxs("div",{className:"relative overflow-hidden rounded-xl p-6 text-center shadow-lg",style:{background:"linear-gradient(135deg, hsl(var(--accent)), hsl(43, 78%, 38%))"},children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.08]",children:e.jsx(St,{className:"h-20 w-20 text-white"})}),e.jsx("p",{className:"text-xs text-white/70 uppercase tracking-wider mb-1 font-medium",children:"Recovery Rate"}),e.jsxs("p",{className:"text-2xl font-heading font-bold text-white",children:[te,"%"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsx(_,{title:"Recovery Cases by Status",dotColor:"hsl(0, 84%, 60%)",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(re,{children:[e.jsx(ae,{data:(t==null?void 0:t.recoveryByStatus)||[],dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",innerRadius:50,outerRadius:80,label:({name:d,value:a})=>`${d}: ${a}`,children:t==null?void 0:t.recoveryByStatus.map((d,a)=>e.jsx(ne,{fill:T[a%T.length]},a))}),e.jsx(N,{content:e.jsx(C,{})})]})})}),e.jsx(_,{title:"Cases by Country",dotColor:"hsl(var(--primary))",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(H,{data:(t==null?void 0:t.recoveryByCountry)||[],children:[e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{dataKey:"name",tick:{fontSize:10}}),e.jsx(U,{tick:{fontSize:11}}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Z,{dataKey:"value",fill:"hsl(var(--primary))",radius:[6,6,0,0]})]})})}),e.jsx(_,{title:"Monthly Recovery Payments (USD)",dotColor:"hsl(142, 76%, 36%)",className:"md:col-span-2",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(H,{data:(t==null?void 0:t.recoveryPaymentTrend)||[],children:[e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{dataKey:"month",tick:{fontSize:11}}),e.jsx(U,{tick:{fontSize:11}}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Z,{dataKey:"amount",fill:"hsl(142, 76%, 36%)",radius:[6,6,0,0]})]})})})]})]})]}),e.jsxs(W,{open:u.starSteel,onOpenChange:()=>D("starSteel"),children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{children:e.jsx(F,{icon:zt,title:"Star Steel Insights",color:"text-indigo-600",dotColor:"hsl(234, 89%, 58%)",isOpen:u.starSteel})})}),e.jsx(G,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mt-4",children:[e.jsx(_,{title:"Assignments by Status",dotColor:"hsl(262, 83%, 58%)",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(H,{data:(t==null?void 0:t.starSteelByStatus)||[],children:[e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{dataKey:"name",tick:{fontSize:11}}),e.jsx(U,{tick:{fontSize:11}}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Z,{dataKey:"value",fill:"hsl(262, 83%, 58%)",radius:[6,6,0,0]})]})})}),e.jsx(_,{title:"Request Type Distribution",dotColor:"hsl(262, 83%, 58%)",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(re,{children:[e.jsx(ae,{data:(t==null?void 0:t.starSteelByType)||[],dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:80,label:({name:d,value:a})=>`${d}: ${a}`,children:t==null?void 0:t.starSteelByType.map((d,a)=>e.jsx(ne,{fill:T[a%T.length]},a))}),e.jsx(N,{content:e.jsx(C,{})})]})})}),e.jsx(_,{title:"Monthly Submission Trend",dotColor:"hsl(262, 83%, 58%)",className:"md:col-span-2",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(Te,{data:(t==null?void 0:t.starSteelMonthly)||[],children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"starSteelGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"hsl(262, 83%, 58%)",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(262, 83%, 58%)",stopOpacity:0})]})}),e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{dataKey:"month",tick:{fontSize:11}}),e.jsx(U,{tick:{fontSize:11}}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Le,{type:"monotone",dataKey:"count",stroke:"hsl(262, 83%, 58%)",strokeWidth:2.5,fill:"url(#starSteelGrad)",dot:{r:3,fill:"hsl(262, 83%, 58%)"}})]})})})]})})]}),e.jsxs(W,{open:u.operational,onOpenChange:()=>D("operational"),children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{children:e.jsx(F,{icon:Ke,title:"Operational Performance",color:"text-amber-600",dotColor:"hsl(38, 92%, 50%)",isOpen:u.operational})})}),e.jsx(G,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mt-4",children:[e.jsxs(L,{className:"relative overflow-hidden border-border/40 bg-gradient-to-br from-blue-500/8 to-blue-500/3 backdrop-blur-sm cursor-pointer hover:shadow-xl hover:scale-[1.03] transition-all duration-300 group",style:{borderLeftWidth:"3px",borderLeftColor:"hsl(200, 80%, 50%)"},onClick:()=>w("avgTurnaround"),children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.06]",children:e.jsx(Ke,{className:"h-20 w-20"})}),e.jsxs(K,{className:"p-5 text-center relative",children:[e.jsx("div",{className:"rounded-xl p-2.5 bg-blue-500/15 mx-auto mb-2 w-fit",children:e.jsx(Ke,{className:"h-7 w-7 text-blue-600"})}),e.jsx("p",{className:"text-3xl font-heading font-bold text-foreground",children:(t==null?void 0:t.avgTurnaroundDays)||0}),e.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"Avg Turnaround (Days)"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"For completed/closed cases"})]})]}),e.jsxs(L,{className:"relative overflow-hidden border-border/40 bg-gradient-to-br from-amber-500/8 to-amber-500/3 backdrop-blur-sm cursor-pointer hover:shadow-xl hover:scale-[1.03] transition-all duration-300 group",style:{borderLeftWidth:"3px",borderLeftColor:"hsl(38, 92%, 50%)"},onClick:()=>w("overdueKYC"),children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.06]",children:e.jsx(Xe,{className:"h-20 w-20"})}),e.jsxs(K,{className:"p-5 text-center relative",children:[e.jsx("div",{className:"rounded-xl p-2.5 bg-amber-500/15 mx-auto mb-2 w-fit",children:e.jsx(Xe,{className:"h-7 w-7 text-amber-600"})}),e.jsx("p",{className:"text-3xl font-heading font-bold text-foreground",children:(t==null?void 0:t.overdueKYCCases)||0}),e.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"Overdue KYC Cases"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Pending > 30 days"})]})]}),e.jsxs(L,{className:"relative overflow-hidden border-border/40 bg-gradient-to-br from-red-500/8 to-red-500/3 backdrop-blur-sm cursor-pointer hover:shadow-xl hover:scale-[1.03] transition-all duration-300 group",style:{borderLeftWidth:"3px",borderLeftColor:"hsl(0, 84%, 60%)"},onClick:()=>w("overdueRecovery"),children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.06]",children:e.jsx(Q,{className:"h-20 w-20"})}),e.jsxs(K,{className:"p-5 text-center relative",children:[e.jsx("div",{className:"rounded-xl p-2.5 bg-red-500/15 mx-auto mb-2 w-fit",children:e.jsx(Q,{className:"h-7 w-7 text-red-600"})}),e.jsx("p",{className:"text-3xl font-heading font-bold text-foreground",children:(t==null?void 0:t.overdueRecoveryCases)||0}),e.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"Overdue Recovery Cases"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Active/Pending > 30 days"})]})]})]})})]}),e.jsxs(W,{open:u.clients,onOpenChange:()=>D("clients"),children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{children:e.jsx(F,{icon:kt,title:"Client Engagement",color:"text-green-600",dotColor:"hsl(142, 76%, 36%)",isOpen:u.clients})})}),e.jsx(G,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mt-4",children:[e.jsx(_,{title:"Top 10 Active Clients (by Cases)",dotColor:"hsl(142, 76%, 36%)",children:e.jsx(v,{config:p,className:"h-72 w-full",children:e.jsxs(H,{data:(t==null?void 0:t.topClients)||[],layout:"vertical",children:[e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{type:"number",tick:{fontSize:11}}),e.jsx(U,{dataKey:"name",type:"category",tick:{fontSize:10},width:120}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Z,{dataKey:"cases",fill:"hsl(142, 76%, 36%)",radius:[0,6,6,0]})]})})}),e.jsx(_,{title:"Login Activity by Day",dotColor:"hsl(var(--primary))",children:e.jsx(v,{config:p,className:"h-72 w-full",children:e.jsxs(H,{data:(t==null?void 0:t.loginFrequency)||[],children:[e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{dataKey:"day",tick:{fontSize:11}}),e.jsx(U,{tick:{fontSize:11}}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Z,{dataKey:"count",fill:"hsl(var(--primary))",radius:[6,6,0,0]})]})})})]})})]}),e.jsxs(W,{open:u.financial,onOpenChange:()=>D("financial"),children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{children:e.jsx(F,{icon:Ze,title:"Financial & System Metrics",color:"text-emerald-600",dotColor:"hsl(142, 76%, 36%)",isOpen:u.financial})})}),e.jsxs(G,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mt-4 mb-6",children:[e.jsxs(L,{className:"relative overflow-hidden border-border/40 bg-gradient-to-br from-green-500/8 to-green-500/3 backdrop-blur-sm",style:{borderLeftWidth:"3px",borderLeftColor:"hsl(142, 76%, 36%)"},children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.06]",children:e.jsx(pe,{className:"h-20 w-20"})}),e.jsxs(K,{className:"p-5 text-center relative",children:[e.jsx("div",{className:"rounded-xl p-2.5 bg-green-500/15 mx-auto mb-2 w-fit",children:e.jsx(pe,{className:"h-7 w-7 text-green-600"})}),e.jsxs("p",{className:"text-3xl font-heading font-bold text-foreground",children:[(t==null?void 0:t.emailSuccessRate)||0,"%"]}),e.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"Email Delivery Rate"})]})]}),e.jsxs(L,{className:"relative overflow-hidden border-border/40 bg-gradient-to-br from-blue-500/8 to-blue-500/3 backdrop-blur-sm",style:{borderLeftWidth:"3px",borderLeftColor:"hsl(200, 80%, 50%)"},children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.06]",children:e.jsx(De,{className:"h-20 w-20"})}),e.jsxs(K,{className:"p-5 text-center relative",children:[e.jsx("div",{className:"rounded-xl p-2.5 bg-blue-500/15 mx-auto mb-2 w-fit",children:e.jsx(De,{className:"h-7 w-7 text-blue-600"})}),e.jsx("p",{className:"text-3xl font-heading font-bold text-foreground",children:(t==null?void 0:t.totalEmailsSent)||0}),e.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"Emails Sent"})]})]}),e.jsxs(L,{className:"relative overflow-hidden border-border/40 bg-gradient-to-br from-red-500/8 to-red-500/3 backdrop-blur-sm",style:{borderLeftWidth:"3px",borderLeftColor:"hsl(0, 84%, 60%)"},children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.06]",children:e.jsx(Q,{className:"h-20 w-20"})}),e.jsxs(K,{className:"p-5 text-center relative",children:[e.jsx("div",{className:"rounded-xl p-2.5 bg-red-500/15 mx-auto mb-2 w-fit",children:e.jsx(Q,{className:"h-7 w-7 text-red-600"})}),e.jsx("p",{className:"text-3xl font-heading font-bold text-foreground",children:(t==null?void 0:t.totalEmailsFailed)||0}),e.jsx("p",{className:"text-xs text-muted-foreground font-medium",children:"Emails Failed"})]})]})]}),e.jsx(_,{title:"Outstanding Debt by Country (USD)",dotColor:"hsl(38, 92%, 50%)",children:e.jsx(v,{config:p,className:"h-64 w-full",children:e.jsxs(H,{data:(t==null?void 0:t.outstandingDebtByCountry)||[],children:[e.jsx($,{strokeDasharray:"3 3",strokeOpacity:.3}),e.jsx(B,{dataKey:"name",tick:{fontSize:10}}),e.jsx(U,{tick:{fontSize:11}}),e.jsx(N,{content:e.jsx(C,{})}),e.jsx(Z,{dataKey:"amount",fill:"hsl(38, 92%, 50%)",radius:[6,6,0,0]})]})})})]})]}),e.jsxs(W,{open:u.governance,onOpenChange:()=>D("governance"),children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{children:e.jsx(F,{icon:Dt,title:"Governance & Compliance",color:"text-primary",dotColor:"hsl(var(--primary))",isOpen:u.governance})})}),e.jsx(G,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6 mt-4",children:[e.jsx(_,{title:"Data Corrections",dotColor:"hsl(var(--primary))",children:e.jsx(v,{config:p,className:"h-56 w-full",children:e.jsxs(re,{children:[e.jsx(ae,{data:(t==null?void 0:t.correctionsByStatus)||[],dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:70,label:!0,children:t==null?void 0:t.correctionsByStatus.map((d,a)=>e.jsx(ne,{fill:T[a%T.length]},a))}),e.jsx(N,{content:e.jsx(C,{})})]})})}),e.jsx(_,{title:"Profile Claims",dotColor:"hsl(var(--accent))",children:e.jsx(v,{config:p,className:"h-56 w-full",children:e.jsxs(re,{children:[e.jsx(ae,{data:(t==null?void 0:t.claimsByStatus)||[],dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:70,label:!0,children:t==null?void 0:t.claimsByStatus.map((d,a)=>e.jsx(ne,{fill:T[a%T.length]},a))}),e.jsx(N,{content:e.jsx(C,{})})]})})}),e.jsxs(L,{className:"relative overflow-hidden flex items-center justify-center border-border/40 bg-gradient-to-br from-green-500/8 to-green-500/3 backdrop-blur-sm",style:{borderLeftWidth:"3px",borderLeftColor:"hsl(142, 76%, 36%)"},children:[e.jsx("div",{className:"absolute top-0 left-0 right-0 h-[3px]",style:{background:"linear-gradient(90deg, hsl(142, 76%, 36%), hsl(142, 76%, 36%, 0.4))"}}),e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.06]",children:e.jsx(pe,{className:"h-20 w-20"})}),e.jsxs(K,{className:"text-center py-8 relative",children:[e.jsx("div",{className:"rounded-xl p-3 bg-green-500/15 mx-auto mb-3 w-fit",children:e.jsx(pe,{className:"h-8 w-8 text-green-600"})}),e.jsx("p",{className:"text-3xl font-heading font-bold text-foreground",children:(t==null?void 0:t.creditConsentCount)||0}),e.jsx("p",{className:"text-sm text-muted-foreground font-medium",children:"Credit Consent Records"})]})]})]})})]}),e.jsxs(W,{open:u.watchlist,onOpenChange:()=>D("watchlist"),children:[e.jsx(Y,{asChild:!0,children:e.jsx("div",{children:e.jsx(F,{icon:Ie,title:"Watchlist & Monitoring",color:"text-primary",dotColor:"hsl(var(--primary))",isOpen:u.watchlist})})}),e.jsx(G,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mt-4",children:[e.jsxs(L,{className:"relative overflow-hidden border-border/40 bg-gradient-to-br from-primary/8 to-primary/3 backdrop-blur-sm",style:{borderLeftWidth:"3px",borderLeftColor:"hsl(var(--primary))"},children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.06]",children:e.jsx(Se,{className:"h-20 w-20"})}),e.jsxs(K,{className:"p-5 flex items-center gap-4 relative",children:[e.jsx("div",{className:"rounded-xl p-3 bg-primary/15 shadow-sm",children:e.jsx(Se,{className:"h-8 w-8 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-3xl font-heading font-bold text-foreground",children:(t==null?void 0:t.companyWatchlistCount)||0}),e.jsx("p",{className:"text-sm text-muted-foreground font-medium",children:"Companies on Watchlist"})]})]})]}),e.jsxs(L,{className:"relative overflow-hidden border-border/40 bg-gradient-to-br from-amber-500/8 to-amber-500/3 backdrop-blur-sm",style:{borderLeftWidth:"3px",borderLeftColor:"hsl(38, 92%, 50%)"},children:[e.jsx("div",{className:"absolute bottom-1 right-1 opacity-[0.06]",children:e.jsx(Q,{className:"h-20 w-20"})}),e.jsxs(K,{className:"p-5 flex items-center gap-4 relative",children:[e.jsx("div",{className:"rounded-xl p-3 bg-amber-500/15 shadow-sm",children:e.jsx(Q,{className:"h-8 w-8 text-amber-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-3xl font-heading font-bold text-foreground",children:(t==null?void 0:t.debtorWatchlistCount)||0}),e.jsx("p",{className:"text-sm text-muted-foreground font-medium",children:"Debtors on Watchlist"})]})]})]})]})})]})]})};export{es as default};
