import{c7 as C,ci as V,bR as T,r as o,p as e,x as E,I as F,bW as S,bA as I,q as d,s as i,H as q,T as k,ai as O,aj as W,ak as x,al as l,aq as A,ar as t,bT as H,aI as R}from"./index-ChEG8aX7.js";import{P as D}from"./pmsReportService-BcAvB_gW.js";const m=n=>new Intl.NumberFormat("en-IN",{minimumFractionDigits:2}).format(n),c=n=>"₹"+new Intl.NumberFormat("en-IN",{minimumFractionDigits:2}).format(n),M=()=>{const{projectId:n}=C(),[v]=V(),_=T(),h=n||v.get("project")||"",[r,w]=o.useState([]),[u,y]=o.useState(""),[P,g]=o.useState(!0);o.useEffect(()=>{if(!h)return;(async()=>{try{g(!0);const a=await D.getVendorProgress(h);w(a.items||a.results||a||[]),y(a.project_name||"")}catch{R.error("Failed to load Vendor Progress report")}finally{g(!1)}})()},[h]);const j=r.reduce((s,a)=>s+a.assigned_quantity,0),N=r.reduce((s,a)=>s+a.executed_quantity,0),p=r.reduce((s,a)=>s+(a.total_value||0),0),f=r.reduce((s,a)=>s+(a.executed_value||0),0),b=j>0?N/j*100:0;return P?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(E,{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(F,{variant:"ghost",size:"icon",onClick:()=>_(-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(I,{className:"h-6 w-6"})," Vendor Progress"]}),u&&e.jsx("p",{className:"text-sm text-muted-foreground",children:u})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(d,{children:e.jsxs(i,{className:"pt-4 pb-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Work Orders"}),e.jsx("p",{className:"text-2xl font-semibold",children:r.length})]})}),e.jsx(d,{children:e.jsxs(i,{className:"pt-4 pb-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Overall Completion"}),e.jsxs("p",{className:"text-2xl font-semibold",children:[b.toFixed(1),"%"]})]})}),e.jsx(d,{children:e.jsxs(i,{className:"pt-4 pb-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total WO Value"}),e.jsx("p",{className:"text-2xl font-semibold",children:c(p)})]})}),e.jsx(d,{children:e.jsxs(i,{className:"pt-4 pb-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Executed Value"}),e.jsx("p",{className:"text-2xl font-semibold",children:c(f)})]})})]}),e.jsxs(d,{children:[e.jsx(q,{children:e.jsx(k,{children:"Vendor-wise Progress"})}),e.jsx(i,{children:e.jsx("div",{className:"rounded-md border overflow-auto",children:e.jsxs(O,{children:[e.jsx(W,{children:e.jsxs(x,{children:[e.jsx(l,{children:"WO Code"}),e.jsx(l,{children:"Vendor"}),e.jsx(l,{className:"text-right",children:"Assigned Qty"}),e.jsx(l,{className:"text-right",children:"Executed Qty"}),e.jsx(l,{className:"w-[180px]",children:"Completion"}),e.jsx(l,{className:"text-right",children:"WO Value"}),e.jsx(l,{className:"text-right",children:"Executed Value"})]})}),e.jsxs(A,{children:[r.length===0?e.jsx(x,{children:e.jsx(t,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"No data available"})}):r.map(s=>e.jsxs(x,{children:[e.jsx(t,{className:"font-mono text-sm",children:s.work_order_code}),e.jsx(t,{children:s.vendor_name}),e.jsx(t,{className:"text-right",children:m(s.assigned_quantity)}),e.jsx(t,{className:"text-right",children:m(s.executed_quantity)}),e.jsx(t,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{value:Math.min(s.completion_percentage,100),className:"h-2 flex-1"}),e.jsxs("span",{className:"text-xs w-12 text-right",children:[s.completion_percentage.toFixed(1),"%"]})]})}),e.jsx(t,{className:"text-right",children:c(s.total_value)}),e.jsx(t,{className:"text-right",children:c(s.executed_value)})]},s.work_order_id)),r.length>0&&e.jsxs(x,{className:"bg-muted/50 font-medium",children:[e.jsx(t,{colSpan:2,className:"text-right",children:"Totals"}),e.jsx(t,{className:"text-right",children:m(j)}),e.jsx(t,{className:"text-right",children:m(N)}),e.jsx(t,{children:e.jsxs("span",{className:"text-xs font-medium",children:[b.toFixed(1),"%"]})}),e.jsx(t,{className:"text-right",children:c(p)}),e.jsx(t,{className:"text-right",children:c(f)})]})]})]})})})]})]})};export{M as default};
