import{bS as E,bT as G,ar as _,db as O,j as a,b as e,f as q,a6 as z,B as h,q as o,g as w,A,i as b,D as x,r as n,a as F,G as C,T as W,o as J,bi as V,e as K,I as u,F as Q}from"./index-ktJf6c6X.js";var p={},$=E;Object.defineProperty(p,"__esModule",{value:!0});var R=p.default=void 0,H=$(G()),U=_;R=p.default=(0,H.default)((0,U.jsx)("path",{d:"M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"}),"CheckSharp");const X=O.injectEndpoints({endpoints:d=>({getCheckerRequests:d.query({query:()=>({url:"checker",method:"GET"})}),getCheckerRequestById:d.query({query:s=>({url:`checker/${s}`,method:"GET"})}),checkerApproval:d.mutation({query:({approvalReq:s})=>({url:"checker/approve",method:"PUT",body:s})})})}),{useLazyGetCheckerRequestsQuery:Y,useLazyGetCheckerRequestByIdQuery:ne,useCheckerApprovalMutation:Z}=X,ee=({open:d,onClose:s,data:r})=>a(x,{open:d,onClose:s,fullWidth:!0,maxWidth:"sm",children:[e(q,{children:"Approval Details"}),e(z,{}),e(w,{children:r&&a(h,{sx:{mt:2},children:[a(o,{variant:"body1",children:[e("strong",{children:"Name:"})," ",r.name]}),a(o,{variant:"body1",children:[e("strong",{children:"Status:"})," ",r.status]}),a(o,{variant:"body1",children:[e("strong",{children:"Requested By:"})," ",r.requestedBy]}),a(o,{variant:"body1",children:[e("strong",{children:"Date:"})," ",r.date]})]})}),e(b,{children:e(A,{btnType:"close",onClick:s,children:"Close"})})]}),l=[{id:1,name:"Purchase Order Approval",status:"Pending",requestedBy:"John Doe",date:"2025-07-24"},{id:2,name:"Material Receive Approval",status:"Approved",requestedBy:"Jane Smith",date:"2025-07-23"},{id:3,name:"Invoice Approval",status:"Rejected",requestedBy:"Alex Lee",date:"2025-07-22"},{id:4,name:"Contract Review",status:"Pending",requestedBy:"Michael Jordan",date:"2025-07-20"},{id:5,name:"Leave Request Approval",status:"Approved",requestedBy:"Kobe Bryant",date:"2025-07-19"},{id:6,name:"Travel Reimbursement",status:"Rejected",requestedBy:"Stephen Curry",date:"2025-07-18"},{id:7,name:"Budget Allocation",status:"Approved",requestedBy:"Tim Duncan",date:"2025-07-17"},{id:8,name:"Training Approval",status:"Pending",requestedBy:"LeBron James",date:"2025-07-16"},{id:9,name:"Performance Bonus",status:"Approved",requestedBy:"Kevin Durant",date:"2025-07-15"},{id:10,name:"Asset Purchase",status:"Rejected",requestedBy:"Shaquille O’Neal",date:"2025-07-14"}],se=()=>{const[d,s]=n.useState([]),[r,k]=n.useState(""),[B]=Y(),[te,{isLoading:S}]=Z(),[D,i]=n.useState(!1),[c,y]=n.useState(null),[ae,m]=n.useState(null),{openSnackbar:v}=F(),[T,f]=n.useState(!1),[j,g]=n.useState(null);n.useEffect(()=>{L()},[]);const L=async()=>{try{const t=await B({});"data"in t?s(t.data.data):v("No data found","warning")}catch{v("Something went wrong while fetching data","error")}},I=t=>{g(t),f(!0)},M=()=>{f(!1),g(null)},N=n.useMemo(()=>l.filter(t=>t.name.toLowerCase().includes(r.toLowerCase())||t.requestedBy.toLowerCase().includes(r.toLowerCase())),[r]),P=[{field:"id",headerName:"ID",width:90},{field:"name",headerName:"Approval Name",flex:1},{field:"requestedBy",headerName:"Requested By",width:200},{field:"date",headerName:"Date",width:150},{field:"actions",headerName:"Actions",width:150,sortable:!1,filterable:!1,renderCell:t=>a(Q,{children:[e(u,{type:"View",onClick:()=>I(t.row)}),e(u,{type:"Custom",icon:e(R,{color:"success"}),onClick:()=>{m(t.row),y("Approved"),i(!0)},tooltipTitle:"Accept"}),e(u,{type:"Close",onClick:()=>{m(t.row),y("Rejected"),i(!0)}})]})}];return a(h,{p:3,sx:{width:"100%"},children:[e(C,{container:!0,justifyContent:"space-between",alignItems:"center",mb:2,children:e(C,{item:!0,children:e(W,{placeholder:"Search by",variant:"outlined",size:"small",sx:{width:225},value:r,onChange:t=>k(t.target.value),InputProps:{startAdornment:e(J,{edge:"end",size:"small",children:e(V,{style:{color:"#bdbdbd"}})})}})})}),l&&(l==null?void 0:l.length)===0?a(h,{sx:{textAlign:"center",py:8},children:[e(o,{variant:"h6",color:"text.secondary",children:"No Checker Requests Found"}),e(o,{variant:"body2",color:"text.secondary",sx:{mt:1},children:"There are currently no requests pending for your review. Please check back later."})]}):e(K,{columns:P,rows:l??[],checkboxSelection:!1,enableManageColumns:!0,defaultHiddenColumns:["id"],rowCount:N.length}),e(ee,{open:T,onClose:M,data:j}),a(x,{open:D,onClose:()=>i(!1),maxWidth:"xs",fullWidth:!0,children:[e(q,{children:c==="Approved"?"Approve Request":"Reject Request"}),e(w,{children:a(o,{children:["Are you sure you want to ",c==null?void 0:c.toLowerCase()," this request?"]})}),e(b,{children:e(A,{btnType:"cancel",onClick:()=>i(!1),disabled:S,children:"Cancel"})})]})]})};export{se as default};
