import{x as C,y as G,r as s,z as Q,ai as _,j as e,B as h,e as $,g as J,T,C as K,P as U}from"./index-B1H8BCL7.js";import{L as z,A as R,D as A,d as v}from"./AdapterDayjs-Bd3f3Uku.js";import{d as V}from"./Search-B5Qac1u3.js";import{A as X}from"./Autocomplete-D8_Y_gp5.js";import{T as Z}from"./TableContainer-CXAjhAg6.js";import{T as ee,c as te,b,a as se}from"./TableRow-BfKE_xn9.js";import{T as r}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 l={fontSize:"0.7rem",fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.05em",py:1.25,px:2,borderBottom:"1px solid #e2e8f0",whiteSpace:"nowrap"},d={fontSize:"0.8125rem",py:1,px:2,borderBottom:"1px solid #f1f5f9"};function re(){const n=C(G),i=(n==null?void 0:n.navType)==="dark"||(n==null?void 0:n.navType)==="ultra-dark",[c,w]=s.useState(null),[x,E]=s.useState(null),[g,N]=s.useState(null),[j,a]=s.useState(""),[m,D]=s.useState([]),[k,M]=s.useState([]),[L,P]=s.useState(""),[O,W]=s.useState(!1),[Y]=Q(),[S,I]=s.useState(),p=C(t=>t.userRole.roleDetails);s.useEffect(()=>{if(p){const t=p.find(o=>o.applicationEntityName.toLowerCase().replace(/\s+/g,"")==="doctor");I(t)}},[p]);const u=_({refetchOnMountOrArgChange:!0});s.useEffect(()=>{u.data&&M(u.data.list)},[u.data]);const B=()=>{if(!g||!c||!x){a("Please provide all required fields (Doctor Name, Start Date, and End Date).");return}a("");const t=v(c).format("YYYY-MM-DD"),o=v(x).format("YYYY-MM-DD"),F={doctorName:g.name,startDate:t,endDate:o};Y(F).unwrap().then(f=>{if(f.code===200){const y=f.list||[];D(y),P(y.reduce((H,q)=>H+q.amount,0)),W(!0)}else D([]),a(f.message)}).catch(()=>{a("Something went wrong, please try again later.")})};return e.jsxs(h,{sx:{px:{xs:1.5,sm:2.5},py:1.5},children:[e.jsxs(h,{sx:{display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",mb:2},children:[e.jsx(X,{sx:{width:{xs:"100%",sm:240}},size:"small",options:k,getOptionLabel:t=>t.name,onChange:(t,o)=>{N(o),a("")},renderInput:t=>e.jsx($,{...t,label:"Doctor Name",sx:{"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}})}),e.jsx(z,{dateAdapter:R,children:e.jsx(A,{label:"Start Date",value:c,onChange:t=>{w(t),a("")},slotProps:{textField:{size:"small",sx:{width:{xs:"100%",sm:200},"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),e.jsx(z,{dateAdapter:R,children:e.jsx(A,{label:"End Date",value:x,onChange:t=>{E(t),a("")},slotProps:{textField:{size:"small",sx:{width:{xs:"100%",sm:200},"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),S&&S.create&&e.jsx(J,{variant:"contained",disableElevation:!0,startIcon:e.jsx(V,{}),onClick:B,sx:{textTransform:"none",borderRadius:"8px",px:2,fontSize:"0.8125rem",fontWeight:600,backgroundColor:"#1d4ed8","&:hover":{backgroundColor:"#1e40af"}},children:"Search"})]}),j&&e.jsx(T,{sx:{color:"#ef4444",fontSize:"0.8125rem",mb:2},children:j}),O&&e.jsxs(e.Fragment,{children:[e.jsxs(h,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2},children:[e.jsx(K,{label:`${m.length} Records`,size:"small",sx:{backgroundColor:i?"rgba(255,255,255,0.08)":"#f1f5f9",color:i?"#e2e8f0":"#475569",fontWeight:600,fontSize:"0.7rem",borderRadius:"6px"}}),e.jsxs(T,{sx:{fontSize:"0.8125rem",fontWeight:600,color:i?"#f1f5f9":"#1e293b"},children:["Total Amount: ",L]})]}),e.jsx(Z,{component:U,variant:"outlined",sx:{borderRadius:2,borderColor:i?"rgba(255,255,255,0.08)":"#e2e8f0",overflow:"auto",boxShadow:"none"},children:e.jsxs(ee,{size:"small",sx:{minWidth:500},children:[e.jsx(te,{children:e.jsxs(b,{sx:{backgroundColor:i?"rgba(255,255,255,0.04)":"#f8fafc"},children:[e.jsx(r,{sx:l,children:"#"}),e.jsx(r,{sx:l,children:"Report No"}),e.jsx(r,{sx:l,children:"Date"}),e.jsx(r,{sx:l,children:"Patient Name"}),e.jsx(r,{sx:{...l,textAlign:"right"},children:"Amount"})]})}),e.jsx(se,{children:m.length===0?e.jsx(b,{children:e.jsx(r,{colSpan:5,sx:{textAlign:"center",py:5,color:"#94a3b8",fontSize:"0.8125rem"},children:"No records found"})}):m.map((t,o)=>e.jsxs(b,{hover:!0,sx:{"&:last-child td, &:last-child th":{border:0},"&:hover":{backgroundColor:i?"rgba(255,255,255,0.03)":"#fafbfe"}},children:[e.jsx(r,{sx:d,children:o+1}),e.jsx(r,{sx:d,children:t.reportNo}),e.jsx(r,{sx:d,children:t.createdDate}),e.jsx(r,{sx:d,children:t.patientName}),e.jsx(r,{sx:{...d,textAlign:"right"},children:t.amount})]},t.reportNo||o))})]})})]})]})}const be=()=>e.jsx(re,{});export{be as default};
