import{bR as k,r as l,c6 as T,aI as I,p as e,I as i,ae as z,q as S,s as b,Q as A,W as E,a9 as L,aa as R,ab as _,ac as B,ad as j,V as F,x as V,ai as Q,aj as U,ak as p,al as r,aq as $,ar as a,B as q,$ as H,a0 as W,a2 as G,a3 as J,a6 as K,aw as O}from"./index-ChEG8aX7.js";const X={10:{label:"Draft",color:"bg-gray-100 text-gray-800"},11:{label:"Active",color:"bg-green-100 text-green-800"},12:{label:"Closed",color:"bg-blue-100 text-blue-800"}},v=t=>t?new Date(t).toLocaleDateString("en-IN",{day:"2-digit",month:"short",year:"numeric"}):"-",Y=t=>t!=null?"₹"+new Intl.NumberFormat("en-IN").format(t):"-",ee=()=>{const t=k(),[f,w]=l.useState([]),[C,N]=l.useState(!0),[d,y]=l.useState(""),[x,P]=l.useState("all"),[n,h]=l.useState(1),[m,D]=l.useState(0),o=20,u=l.useCallback(async()=>{try{N(!0);const s=new URLSearchParams;s.set("page",String(n)),s.set("page_size",String(o)),d&&s.set("search",d),x!=="all"&&s.set("status",x),s.set("ordering","-created_on");const c=await T.getProjects(s.toString());w(c.results||c||[]),D(c.count||0)}catch(s){console.error("Error fetching PMS projects:",s),I.error("Failed to load PMS projects")}finally{N(!1)}},[n,d,x]);l.useEffect(()=>{u()},[u]);const M=s=>{s.preventDefault(),h(1),u()};return e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"PMS Projects"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage sub-contract work order projects"})]}),e.jsxs(i,{onClick:()=>t("/projectmanagement/pms/projects/create"),children:[e.jsx(z,{className:"h-4 w-4 mr-2"})," New Project"]})]}),e.jsx(S,{children:e.jsx(b,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("form",{onSubmit:M,className:"flex-1 flex gap-2",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(A,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(E,{placeholder:"Search projects...",value:d,onChange:s=>y(s.target.value),className:"pl-9"})]})}),e.jsxs(L,{value:x,onValueChange:s=>{P(s),h(1)},children:[e.jsx(R,{className:"w-[140px]",children:e.jsx(_,{placeholder:"Status"})}),e.jsxs(B,{children:[e.jsx(j,{value:"all",children:"All Status"}),e.jsx(j,{value:"10",children:"Draft"}),e.jsx(j,{value:"11",children:"Active"}),e.jsx(j,{value:"12",children:"Closed"})]})]}),e.jsx(i,{variant:"outline",size:"icon",onClick:u,children:e.jsx(F,{className:"h-4 w-4"})})]})})}),e.jsxs(S,{children:[e.jsx(b,{className:"p-0",children:C?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(V,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(Q,{children:[e.jsx(U,{children:e.jsxs(p,{children:[e.jsx(r,{children:"Code"}),e.jsx(r,{children:"Project Name"}),e.jsx(r,{children:"Client"}),e.jsx(r,{children:"Location"}),e.jsx(r,{children:"Start Date"}),e.jsx(r,{children:"Due Date"}),e.jsx(r,{className:"text-right",children:"Amount"}),e.jsx(r,{children:"Status"}),e.jsx(r,{className:"w-[50px]"})]})}),e.jsx($,{children:f.length===0?e.jsx(p,{children:e.jsx(a,{colSpan:9,className:"text-center py-12 text-muted-foreground",children:"No PMS projects found"})}):f.map(s=>{const c=X[s.status]||{label:"Unknown",color:"bg-gray-100 text-gray-800"};return e.jsxs(p,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>t(`/projectmanagement/pms/projects/${s.id}`),children:[e.jsx(a,{className:"font-mono text-sm",children:s.code||"-"}),e.jsx(a,{className:"font-medium",children:s.name}),e.jsx(a,{children:s.customer?.name||"-"}),e.jsx(a,{children:s.location||"-"}),e.jsx(a,{className:"text-sm",children:v(s.start_date)}),e.jsx(a,{className:"text-sm",children:v(s.due_date)}),e.jsx(a,{className:"text-right",children:Y(s.amount)}),e.jsx(a,{children:e.jsx(q,{className:c.color,children:c.label})}),e.jsx(a,{children:e.jsxs(H,{children:[e.jsx(W,{asChild:!0,onClick:g=>g.stopPropagation(),children:e.jsx(i,{variant:"ghost",size:"icon",className:"h-8 w-8",children:e.jsx(G,{className:"h-4 w-4"})})}),e.jsx(J,{align:"end",children:e.jsxs(K,{onClick:g=>{g.stopPropagation(),t(`/projectmanagement/pms/projects/${s.id}`)},children:[e.jsx(O,{className:"h-4 w-4 mr-2"})," View"]})})]})})]},s.id)})})]})})}),m>o&&e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Showing ",(n-1)*o+1,"-",Math.min(n*o,m)," of ",m]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(i,{variant:"outline",size:"sm",disabled:n<=1,onClick:()=>h(s=>s-1),children:"Previous"}),e.jsx(i,{variant:"outline",size:"sm",disabled:n*o>=m,onClick:()=>h(s=>s+1),children:"Next"})]})]})]})]})};export{ee as default};
