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{r as _}from"./calculations-Djz1Ahac.js";var v=e(t()),y=n();function b(){let{data:e=[]}=h(`AEN`),{data:t=[]}=m(),n=(0,v.useMemo)(()=>new Map(t.map(e=>[e.sr_no,e.weightage??0])),[t]),b=(0,v.useMemo)(()=>e.map(e=>{let t=n.get(e.item_sr_no)??e.weightage??0,r=_(e.cum_progress,e.cum_scope),i=null;return t>=1&&r<60?i=`red`:t===.5&&r<75&&(i=`amber`),{...e,weight:t,compliance:r,severity:i}}).filter(e=>e.severity!==null).sort((e,t)=>(e.severity===`red`?-1:1)-(t.severity===`red`?-1:1)||e.compliance-t.compliance),[e,n]),x=b.filter(e=>e.severity===`red`),S=b.filter(e=>e.severity===`amber`);return(0,y.jsxs)(`div`,{className:`p-6 max-w-[1600px] mx-auto`,children:[(0,y.jsx)(r,{title:`Alerts & Exceptions`,subtitle:`Automatically generated based on risk weight and compliance thresholds.`}),(0,y.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 mb-4`,children:[(0,y.jsxs)(s,{className:`border-destructive/50`,children:[(0,y.jsx)(o,{children:(0,y.jsx)(i,{className:`text-destructive`,children:`Red alerts`})}),(0,y.jsxs)(a,{children:[(0,y.jsx)(`div`,{className:`text-3xl font-semibold`,children:x.length}),(0,y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:`Weight ≥ 1 and compliance < 60%`})]})]}),(0,y.jsxs)(s,{className:`border-warning/40`,children:[(0,y.jsx)(o,{children:(0,y.jsx)(i,{style:{color:`oklch(0.55 0.18 45)`},children:`Amber alerts`})}),(0,y.jsxs)(a,{children:[(0,y.jsx)(`div`,{className:`text-3xl font-semibold`,children:S.length}),(0,y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:`Weight = 0.5 and compliance < 75%`})]})]})]}),(0,y.jsxs)(s,{children:[(0,y.jsx)(o,{children:(0,y.jsx)(i,{children:`Open alerts`})}),(0,y.jsx)(a,{className:`p-0`,children:(0,y.jsx)(`div`,{className:`max-h-[65vh] overflow-auto`,children:(0,y.jsxs)(p,{children:[(0,y.jsx)(u,{className:`sticky top-0 bg-card z-10`,children:(0,y.jsxs)(f,{children:[(0,y.jsx)(c,{children:`Severity`}),(0,y.jsx)(c,{children:`Item`}),(0,y.jsx)(c,{children:`Division`}),(0,y.jsx)(c,{children:`AEN`}),(0,y.jsx)(c,{className:`text-right`,children:`Weight`}),(0,y.jsx)(c,{className:`text-right`,children:`Compliance`}),(0,y.jsx)(c,{className:`text-right`,children:`Cum Scope`}),(0,y.jsx)(c,{className:`text-right`,children:`Cum Progress`})]})}),(0,y.jsxs)(l,{children:[b.map(e=>(0,y.jsxs)(f,{children:[(0,y.jsx)(d,{children:e.severity===`red`?(0,y.jsx)(g,{variant:`destructive`,children:`RED`}):(0,y.jsx)(g,{style:{backgroundColor:`oklch(0.72 0.18 45)`,color:`white`},children:`AMBER`})}),(0,y.jsxs)(d,{className:`max-w-[280px]`,children:[(0,y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.item_sr_no}),(0,y.jsx)(`div`,{className:`truncate`,children:e.item_name})]}),(0,y.jsx)(d,{children:e.division}),(0,y.jsx)(d,{children:e.aen}),(0,y.jsx)(d,{className:`text-right`,children:e.weight.toFixed(2)}),(0,y.jsxs)(d,{className:`text-right`,children:[e.compliance.toFixed(1),`%`]}),(0,y.jsx)(d,{className:`text-right`,children:e.cum_scope}),(0,y.jsx)(d,{className:`text-right`,children:e.cum_progress})]},e.id)),b.length===0&&(0,y.jsx)(f,{children:(0,y.jsx)(d,{colSpan:8,className:`text-center text-sm text-muted-foreground py-8`,children:`No open alerts.`})})]})]})})})]})]})}export{b as component};