import{c7 as C,ci as P,bR as T,r as i,p as e,x as y,I,bW as S,c5 as k,q as c,s as d,H as _,T as q,ai as B,aj as A,ak as o,al as l,aq as O,ar as r,bT as E,B as F,aI as H}from"./index-ChEG8aX7.js";import{P as L}from"./pmsReportService-BcAvB_gW.js";const R=n=>n>100?{badge:"bg-red-100 text-red-800",bar:"bg-red-500",label:"Over"}:n>=90?{badge:"bg-amber-100 text-amber-800",bar:"bg-amber-500",label:"Near"}:{badge:"bg-green-100 text-green-800",bar:"bg-green-500",label:"On Track"},j=n=>new Intl.NumberFormat("en-IN",{minimumFractionDigits:2}).format(n),Q=()=>{const{projectId:n}=C(),[u]=P(),g=T(),x=n||u.get("project")||"",[t,p]=i.useState([]),[m,b]=i.useState(""),[N,h]=i.useState(!0);i.useEffect(()=>{if(!x)return;(async()=>{try{h(!0);const a=await L.getPlannedVsActual(x);p(a.items||a.results||a||[]),b(a.project_name||"")}catch{H.error("Failed to load Planned vs Actual report")}finally{h(!1)}})()},[x]),t.reduce((s,a)=>s+a.planned_quantity,0),t.reduce((s,a)=>s+a.executed_quantity,0);const f=t.filter(s=>s.percentage>100).length,v=t.filter(s=>s.percentage>=90&&s.percentage<=100).length,w=t.filter(s=>s.percentage<90).length;return N?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(y,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4 p-4 max-w-6xl mx-auto",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(I,{variant:"ghost",size:"icon",onClick:()=>g(-1),children:e.jsx(S,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-semibold flex items-center gap-2",children:[e.jsx(k,{className:"h-6 w-6"})," Planned vs Actual"]}),m&&e.jsx("p",{className:"text-sm text-muted-foreground",children:m})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(c,{children:e.jsxs(d,{className:"pt-4 pb-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total BoQ Items"}),e.jsx("p",{className:"text-2xl font-semibold",children:t.length})]})}),e.jsx(c,{children:e.jsxs(d,{className:"pt-4 pb-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 inline-block"})," On Track (≤90%)"]}),e.jsx("p",{className:"text-2xl font-semibold text-green-700",children:w})]})}),e.jsx(c,{children:e.jsxs(d,{className:"pt-4 pb-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-amber-500 inline-block"})," Near Limit (90-100%)"]}),e.jsx("p",{className:"text-2xl font-semibold text-amber-700",children:v})]})}),e.jsx(c,{children:e.jsxs(d,{className:"pt-4 pb-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500 inline-block"})," Over (>100%)"]}),e.jsx("p",{className:"text-2xl font-semibold text-red-700",children:f})]})})]}),e.jsxs(c,{children:[e.jsx(_,{children:e.jsx(q,{children:"BoQ Item Comparison"})}),e.jsx(d,{children:e.jsx("div",{className:"rounded-md border overflow-auto",children:e.jsxs(B,{children:[e.jsx(A,{children:e.jsxs(o,{children:[e.jsx(l,{children:"Item Code"}),e.jsx(l,{children:"Description"}),e.jsx(l,{children:"UOM"}),e.jsx(l,{className:"text-right",children:"Planned"}),e.jsx(l,{className:"text-right",children:"Executed"}),e.jsx(l,{className:"w-[180px]",children:"Progress"}),e.jsx(l,{className:"text-center",children:"Status"})]})}),e.jsx(O,{children:t.length===0?e.jsx(o,{children:e.jsx(r,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"No data available"})}):t.map(s=>{const a=R(s.percentage);return e.jsxs(o,{children:[e.jsx(r,{className:"font-mono text-sm",children:s.item_code}),e.jsx(r,{className:"max-w-[200px] truncate",children:s.description}),e.jsx(r,{children:s.uom}),e.jsx(r,{className:"text-right",children:j(s.planned_quantity)}),e.jsx(r,{className:"text-right",children:j(s.executed_quantity)}),e.jsx(r,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{value:Math.min(s.percentage,100),className:"h-2 flex-1"}),e.jsxs("span",{className:"text-xs w-12 text-right",children:[s.percentage.toFixed(1),"%"]})]})}),e.jsx(r,{className:"text-center",children:e.jsx(F,{className:a.badge,children:a.label})})]},s.boq_item_id)})})]})})})]})]})};export{Q as default};
