import{_ as I,h as r,j as e,$ as q,A,u as G,G as C,i as E,F}from"./index-Da-VPv7f.js";import{r as n,aj as O,aD as W,aE as _,aF as $}from"./mui-icons-CVqIXJUc.js";import{D as z,l as m,k as J,I as u,x as p}from"./mui-x-datagrid-D42xrz8e.js";import{T as o}from"./mui-x-charts-CP3e2jhe.js";import{D as b,b as k,c as B}from"./mui-x-pickers-BflNfF54.js";const V=I.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:K,useLazyGetCheckerRequestByIdQuery:ae,useCheckerApprovalMutation:Q}=V,H=({open:d,onClose:s,data:a})=>r(B,{open:d,onClose:s,fullWidth:!0,maxWidth:"sm",children:[e(q,{children:"Approval Details"}),e(z,{}),e(b,{children:a&&r(m,{sx:{mt:2},children:[r(o,{variant:"body1",children:[e("strong",{children:"Name:"})," ",a.name]}),r(o,{variant:"body1",children:[e("strong",{children:"Status:"})," ",a.status]}),r(o,{variant:"body1",children:[e("strong",{children:"Requested By:"})," ",a.requestedBy]}),r(o,{variant:"body1",children:[e("strong",{children:"Date:"})," ",a.date]})]})}),e(k,{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"}],ne=()=>{const[d,s]=n.useState([]),[a,R]=n.useState(""),[x]=K(),[U,{isLoading:h}]=Q(),[D,i]=n.useState(!1),[c,y]=n.useState(null),[X,f]=n.useState(null),{openSnackbar:v}=G(),[S,g]=n.useState(!1),[T,w]=n.useState(null);n.useEffect(()=>{j()},[]);const j=async()=>{try{const t=await x({});"data"in t?s(t.data.data):v("No data found","warning")}catch{v("Something went wrong while fetching data","error")}},L=t=>{w(t),g(!0)},N=()=>{g(!1),w(null)},M=n.useMemo(()=>l.filter(t=>t.name.toLowerCase().includes(a.toLowerCase())||t.requestedBy.toLowerCase().includes(a.toLowerCase())),[a]),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=>r(F,{children:[e(p,{title:"View",children:e(u,{onClick:()=>L(t.row),children:e(W,{color:"primary"})})}),e(p,{title:"Accept",children:e(u,{disabled:h,onClick:()=>{f(t.row),y("Approved"),i(!0)},children:e(_,{color:"success"})})}),e(p,{title:"Reject",children:e(u,{disabled:h,onClick:()=>{f(t.row),y("Rejected"),i(!0)},children:e($,{color:"error"})})})]})}];return r(m,{p:3,sx:{width:"100%"},children:[e(C,{container:!0,justifyContent:"space-between",alignItems:"center",mb:2,children:e(C,{item:!0,children:e(J,{placeholder:"Search by",variant:"outlined",size:"small",sx:{width:225},value:a,onChange:t=>R(t.target.value),InputProps:{startAdornment:e(u,{edge:"end",size:"small",children:e(O,{style:{color:"#bdbdbd"}})})}})})}),l&&(l==null?void 0:l.length)===0?r(m,{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(E,{columns:P,rows:l??[],checkboxSelection:!1,enableManageColumns:!0,defaultHiddenColumns:["id"],rowCount:M.length}),e(H,{open:S,onClose:N,data:T}),r(B,{open:D,onClose:()=>i(!1),maxWidth:"xs",fullWidth:!0,children:[e(q,{children:c==="Approved"?"Approve Request":"Reject Request"}),e(b,{children:r(o,{children:["Are you sure you want to ",c==null?void 0:c.toLowerCase()," this request?"]})}),e(k,{children:e(A,{btnType:"cancel",onClick:()=>i(!1),disabled:h,children:"Cancel"})})]})]})};export{ne as default};
