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{n as c,r as l}from"./data-hooks-B3BJoiaE.js";import{o as u,r as d}from"./calculations-Djz1Ahac.js";import{i as f,n as p,r as m,t as h}from"./tabs-DFilYnmT.js";var g=e(t()),_=n();function v({label:e,value:t,sub:n}){return(0,_.jsxs)(`div`,{className:`rounded-md p-3 text-center ${u(t)}`,children:[(0,_.jsx)(`div`,{className:`text-xs opacity-80 truncate`,title:e,children:e}),(0,_.jsxs)(`div`,{className:`text-lg font-semibold mt-1`,children:[t.toFixed(0),`%`]}),n&&(0,_.jsx)(`div`,{className:`text-[10px] opacity-70 mt-0.5`,children:n})]})}function y(){let{data:e=[]}=l(`AEN`),{data:t=[]}=l(`SSE`),{data:n=[]}=c(),u=(0,g.useMemo)(()=>{let t=new Map;for(let n of e){t.has(n.division)||t.set(n.division,{s:0,p:0});let e=t.get(n.division);e.s+=n.cum_scope,e.p+=n.cum_progress}return Array.from(t.entries()).map(([e,t])=>({k:e,c:d(t.p,t.s)}))},[e]),y=(0,g.useMemo)(()=>{let t=new Map;for(let n of e){let e=`${n.division}|${n.aen}`;t.has(e)||t.set(e,{div:n.division,aen:n.aen,s:0,p:0});let r=t.get(e);r.s+=n.cum_scope,r.p+=n.cum_progress}return Array.from(t.values()).map(e=>({...e,c:d(e.p,e.s)}))},[e]),b=(0,g.useMemo)(()=>{let e=new Map;for(let n of t){if(!n.sse)continue;let t=`${n.division}|${n.aen}|${n.sse}`;e.has(t)||e.set(t,{div:n.division,aen:n.aen,sse:n.sse,s:0,p:0});let r=e.get(t);r.s+=n.cum_scope,r.p+=n.cum_progress}return Array.from(e.values()).map(e=>({...e,c:d(e.p,e.s)}))},[t]),x=(0,g.useMemo)(()=>{let t=new Map(n.map(e=>[e.sr_no,e.name])),r=new Map;for(let t of e){r.has(t.item_sr_no)||r.set(t.item_sr_no,{sr:t.item_sr_no,s:0,p:0});let e=r.get(t.item_sr_no);e.s+=t.cum_scope,e.p+=t.cum_progress}return Array.from(r.values()).map(e=>({...e,c:d(e.p,e.s),name:t.get(e.sr)??e.sr})).sort((e,t)=>e.c-t.c)},[e,n]);return(0,_.jsxs)(`div`,{className:`p-6 max-w-[1600px] mx-auto`,children:[(0,_.jsx)(r,{title:`Heat Maps`,subtitle:`Compliance colours — green ≥ 90%, yellow 70–90%, orange 50–70%, red < 50%.`}),(0,_.jsxs)(h,{defaultValue:`division`,children:[(0,_.jsxs)(m,{children:[(0,_.jsx)(f,{value:`division`,children:`Divisions`}),(0,_.jsx)(f,{value:`aen`,children:`AENs`}),(0,_.jsx)(f,{value:`sse`,children:`SSEs`}),(0,_.jsx)(f,{value:`item`,children:`Items`})]}),(0,_.jsx)(p,{value:`division`,children:(0,_.jsxs)(s,{children:[(0,_.jsx)(o,{children:(0,_.jsx)(i,{children:`Division Heat Map`})}),(0,_.jsx)(a,{children:(0,_.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-3`,children:u.map(e=>(0,_.jsx)(v,{label:e.k,value:e.c},e.k))})})]})}),(0,_.jsx)(p,{value:`aen`,children:(0,_.jsxs)(s,{children:[(0,_.jsx)(o,{children:(0,_.jsx)(i,{children:`AEN Heat Map`})}),(0,_.jsx)(a,{children:(0,_.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3`,children:y.map(e=>(0,_.jsx)(v,{label:e.aen,value:e.c,sub:e.div},`${e.div}-${e.aen}`))})})]})}),(0,_.jsx)(p,{value:`sse`,children:(0,_.jsxs)(s,{children:[(0,_.jsx)(o,{children:(0,_.jsx)(i,{children:`SSE Heat Map`})}),(0,_.jsx)(a,{children:(0,_.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3`,children:b.map(e=>(0,_.jsx)(v,{label:e.sse,value:e.c,sub:`${e.div} · ${e.aen}`},`${e.div}-${e.aen}-${e.sse}`))})})]})}),(0,_.jsx)(p,{value:`item`,children:(0,_.jsxs)(s,{children:[(0,_.jsx)(o,{children:(0,_.jsx)(i,{children:`Item Heat Map (lowest compliance first)`})}),(0,_.jsx)(a,{children:(0,_.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3`,children:x.slice(0,60).map(e=>(0,_.jsx)(v,{label:e.name,value:e.c,sub:e.sr},e.sr))})})]})})]})]})}export{y as component};