import{x as C,y as I,r as o,z as L,j as e,B as g,g as F,T as R,C as O,P as H}from"./index-B1H8BCL7.js";import{L as w,A as z,D as A,d as r}from"./AdapterDayjs-Bd3f3Uku.js";import{d as _}from"./Search-B5Qac1u3.js";import{T as $}from"./TableContainer-CXAjhAg6.js";import{T as q,c as G,b as j,a as J}from"./TableRow-BfKE_xn9.js";import{T as s}from"./TableCell-D8CotAsC.js";import"./useThemeProps-DcBTMaaC.js";import"./useThemeProps-DL_l3A7P.js";import"./Grid-CTEl0Elf.js";import"./colorManipulator-B4HuGLt1.js";import"./useSlotProps-eBp3I9mO.js";import"./InputAdornment-BMBVR6Ec.js";const f={fontSize:"0.7rem",fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.05em",py:1.25,px:2,borderBottom:"1px solid #e2e8f0",whiteSpace:"nowrap"},p={fontSize:"0.8125rem",py:1,px:2,borderBottom:"1px solid #f1f5f9"};function K(){const n=C(I),l=(n==null?void 0:n.navType)==="dark"||(n==null?void 0:n.navType)==="ultra-dark",[i,v]=o.useState(null),[c,k]=o.useState(null),[y,m]=o.useState(""),[h,D]=o.useState([]),[M,P]=o.useState(""),[W,S]=o.useState(!1),[T,E]=o.useState(),b=C(t=>t.userRole.roleDetails);o.useEffect(()=>{if(b){const t=b.find(a=>a.applicationEntityName.toLowerCase().replace(/\s+/g,"")==="day");E(t)}},[b]);const[Y]=L(),B=()=>{if(!i||!c){m("Please select both start and end dates.");return}m("");const t={startDate:r(i).format("YYYY-MM-DD"),endDate:r(c).format("YYYY-MM-DD")};Y(t).unwrap().then(a=>{if(a.code===200){let d=a.list;r(i).isSame(r(c),"day")?d=d.filter(x=>r(x.createdDate).isSame(r(i),"day")):d=d.filter(x=>{const u=r(x.createdDate);return u.isAfter(r(i).subtract(1,"day"))&&u.isBefore(r(c).add(1,"day"))}),D(d);const N=d.reduce((x,u)=>x+u.amount,0);P(N),S(!0)}else D([]),m(a.message),S(!1)}).catch(a=>{console.error(a),m("Something went wrong, please try again later.")})};return e.jsxs(g,{sx:{px:{xs:1.5,sm:2.5},py:1.5},children:[e.jsxs(g,{sx:{display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",mb:2},children:[e.jsx(w,{dateAdapter:z,children:e.jsx(A,{label:"From Date",value:i,onChange:t=>v(t),slotProps:{textField:{size:"small",sx:{width:{xs:"100%",sm:200},"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),e.jsx(w,{dateAdapter:z,children:e.jsx(A,{label:"To Date",value:c,onChange:t=>k(t),slotProps:{textField:{size:"small",sx:{width:{xs:"100%",sm:200},"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),T&&T.create&&e.jsx(F,{variant:"contained",disableElevation:!0,startIcon:e.jsx(_,{}),onClick:B,sx:{textTransform:"none",borderRadius:"8px",px:2,fontSize:"0.8125rem",fontWeight:600,backgroundColor:"#1d4ed8","&:hover":{backgroundColor:"#1e40af"}},children:"Search"})]}),y&&e.jsx(R,{sx:{color:"#ef4444",fontSize:"0.8125rem",mb:2},children:y}),W&&e.jsxs(e.Fragment,{children:[e.jsxs(g,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2},children:[e.jsx(O,{label:`${h.length} Records`,size:"small",sx:{backgroundColor:l?"rgba(255,255,255,0.08)":"#f1f5f9",color:l?"#e2e8f0":"#475569",fontWeight:600,fontSize:"0.7rem",borderRadius:"6px"}}),e.jsxs(R,{sx:{fontSize:"0.8125rem",fontWeight:600,color:l?"#f1f5f9":"#1e293b"},children:["Total Amount: ",M]})]}),e.jsx($,{component:H,variant:"outlined",sx:{borderRadius:2,borderColor:l?"rgba(255,255,255,0.08)":"#e2e8f0",overflow:"auto",boxShadow:"none"},children:e.jsxs(q,{size:"small",sx:{minWidth:500},children:[e.jsx(G,{children:e.jsxs(j,{sx:{backgroundColor:l?"rgba(255,255,255,0.04)":"#f8fafc"},children:[e.jsx(s,{sx:f,children:"#"}),e.jsx(s,{sx:f,children:"Report No"}),e.jsx(s,{sx:f,children:"Date"}),e.jsx(s,{sx:f,children:"Patient Name"}),e.jsx(s,{sx:{...f,textAlign:"right"},children:"Amount"})]})}),e.jsx(J,{children:h.length===0?e.jsx(j,{children:e.jsx(s,{colSpan:5,sx:{textAlign:"center",py:5,color:"#94a3b8",fontSize:"0.8125rem"},children:"No records found"})}):h.map((t,a)=>e.jsxs(j,{hover:!0,sx:{"&:last-child td, &:last-child th":{border:0},"&:hover":{backgroundColor:l?"rgba(255,255,255,0.03)":"#fafbfe"}},children:[e.jsx(s,{sx:p,children:a+1}),e.jsx(s,{sx:p,children:t.reportNo}),e.jsx(s,{sx:p,children:t.createdDate}),e.jsx(s,{sx:p,children:t.patientName}),e.jsx(s,{sx:{...p,textAlign:"right"},children:t.amount})]},t.reportNo||a))})]})})]})]})}const le=()=>e.jsx(K,{});export{le as default};
