import{i as e,n as t,t as n}from"./jsx-runtime-bzQ4Vb5N.js";import{t as r}from"./page-header-CqpDR1d0.js";import{i,n as a,r as o,t as s}from"./card-2XLQ4Sqm.js";import{a as c,n as l,o as u,r as d,s as f,t as p}from"./table-CVkwN17b.js";import{n as m,r as h}from"./data-hooks-B3BJoiaE.js";import{t as g}from"./badge-7GJDNue6.js";import{i as _,r as v}from"./calculations-Djz1Ahac.js";var y=e(t()),b=n();function x(){let{data:e=[]}=h(`AEN`),{data:t=[]}=h(`SSE`),{data:n=[]}=m(),i=(0,y.useMemo)(()=>new Map(n.map(e=>[e.sr_no,e.weightage??0])),[n]),a=e=>e.map(e=>({...e,compliance:e.cumScope>0?e.cumProg/e.cumScope*100:0,wCompAvg:e.w>0?e.wComp/e.w:0})).sort((e,t)=>t.wCompAvg-e.wCompAvg),o=(0,y.useMemo)(()=>{let t=new Map;for(let n of e){let e=i.get(n.item_sr_no)??n.weightage??0,r=v(n.cum_progress,n.cum_scope);t.has(n.division)||t.set(n.division,{key:n.division,w:0,wComp:0,cumScope:0,cumProg:0,deficit:0});let a=t.get(n.division);a.w+=e,a.wComp+=r*e,a.cumScope+=n.cum_scope,a.cumProg+=n.cum_progress,a.deficit+=_(r,e)}return a(Array.from(t.values()))},[e,i]),s=(0,y.useMemo)(()=>{let t=new Map;for(let n of e){let e=i.get(n.item_sr_no)??n.weightage??0,r=v(n.cum_progress,n.cum_scope),a=`${n.division}|${n.aen}`;t.has(a)||t.set(a,{key:a,division:n.division,aen:n.aen,w:0,wComp:0,cumScope:0,cumProg:0,deficit:0});let o=t.get(a);o.w+=e,o.wComp+=r*e,o.cumScope+=n.cum_scope,o.cumProg+=n.cum_progress,o.deficit+=_(r,e)}return a(Array.from(t.values()))},[e,i]),c=(0,y.useMemo)(()=>{let e=new Map;for(let n of t){if(!n.sse)continue;let t=i.get(n.item_sr_no)??n.weightage??0,r=v(n.cum_progress,n.cum_scope),a=`${n.division}|${n.aen}|${n.sse}`;e.has(a)||e.set(a,{key:a,division:n.division,aen:n.aen,sse:n.sse,w:0,wComp:0,cumScope:0,cumProg:0,deficit:0});let o=e.get(a);o.w+=t,o.wComp+=r*t,o.cumScope+=n.cum_scope,o.cumProg+=n.cum_progress,o.deficit+=_(r,t)}return a(Array.from(e.values())).slice(0,30)},[t,i]);return(0,b.jsxs)(`div`,{className:`p-6 max-w-[1600px] mx-auto`,children:[(0,b.jsx)(r,{title:`Rankings & Scorecards`,subtitle:`Ranked by weighted compliance (higher is better).`}),(0,b.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-3 gap-4`,children:[(0,b.jsx)(S,{title:`Divisions`,rows:o.map((e,t)=>({rank:t+1,name:e.key,sub:null,comp:e.compliance,wcomp:e.wCompAvg,deficit:e.deficit}))}),(0,b.jsx)(S,{title:`AENs`,rows:s.map((e,t)=>({rank:t+1,name:e.aen,sub:e.division,comp:e.compliance,wcomp:e.wCompAvg,deficit:e.deficit}))}),(0,b.jsx)(S,{title:`SSEs (top 30)`,rows:c.map((e,t)=>({rank:t+1,name:e.sse,sub:`${e.division} · ${e.aen}`,comp:e.compliance,wcomp:e.wCompAvg,deficit:e.deficit}))})]})]})}function S({title:e,rows:t}){return(0,b.jsxs)(s,{children:[(0,b.jsx)(o,{children:(0,b.jsx)(i,{children:e})}),(0,b.jsx)(a,{className:`p-0`,children:(0,b.jsxs)(p,{children:[(0,b.jsx)(u,{children:(0,b.jsxs)(f,{children:[(0,b.jsx)(c,{children:`#`}),(0,b.jsx)(c,{children:`Name`}),(0,b.jsx)(c,{className:`text-right`,children:`Comp.`}),(0,b.jsx)(c,{className:`text-right`,children:`Weighted`})]})}),(0,b.jsxs)(l,{children:[t.map(e=>(0,b.jsxs)(f,{children:[(0,b.jsx)(d,{children:(0,b.jsxs)(g,{variant:`outline`,children:[`#`,e.rank]})}),(0,b.jsxs)(d,{children:[(0,b.jsx)(`div`,{className:`font-medium`,children:e.name}),e.sub&&(0,b.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.sub})]}),(0,b.jsxs)(d,{className:`text-right`,children:[e.comp.toFixed(1),`%`]}),(0,b.jsxs)(d,{className:`text-right`,children:[e.wcomp.toFixed(1),`%`]})]},e.rank+e.name)),t.length===0&&(0,b.jsx)(f,{children:(0,b.jsx)(d,{colSpan:4,className:`text-center text-sm text-muted-foreground py-6`,children:`No data.`})})]})]})})]})}export{x as component};