import{x as H,y as U,r as c,z as q,R as Y,j as t,B as v,g as R,C as G,e as J,T as K,P as Q}from"./index-B1H8BCL7.js";import{L as M,A as F,D as E,d as h}from"./AdapterDayjs-Bd3f3Uku.js";import{d as k}from"./Search-B5Qac1u3.js";import{d as X}from"./FileDownloadOutlined-B1TjRPKt.js";import{d as Z}from"./PictureAsPdfOutlined-CVvvjkcz.js";import{E as ee}from"./jspdf.es.min-BnkKWiZd.js";import"./jspdf.plugin.autotable-BG0-8GHU.js";import{F as te}from"./FileSaver.min-B0uEGt1F.js";import{I as oe}from"./InputAdornment-BMBVR6Ec.js";import{T as se}from"./TableContainer-CXAjhAg6.js";import{T as re,c as ae,b as A,a as ne}from"./TableRow-BfKE_xn9.js";import{T as r}from"./TableCell-D8CotAsC.js";import{T as ie}from"./TablePagination-CVPyh-M-.js";import"./useThemeProps-DcBTMaaC.js";import"./useThemeProps-DL_l3A7P.js";import"./Grid-CTEl0Elf.js";import"./colorManipulator-B4HuGLt1.js";import"./useSlotProps-eBp3I9mO.js";import"./KeyboardArrowRight-DXPl9fjq.js";import"./LastPage-BEvmfPvn.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"},n={fontSize:"0.8125rem",py:1,px:2,borderBottom:"1px solid #f1f5f9"};function Pe(){const x=H(U),l=(x==null?void 0:x.navType)==="dark"||(x==null?void 0:x.navType)==="ultra-dark",[m,W]=c.useState(null),[g,I]=c.useState(null),[w,D]=c.useState([]),[P,b]=c.useState(""),[j,C]=c.useState(0),[p,O]=c.useState(10),[T,_]=c.useState(""),[L]=q(),$=()=>{if(!m||!g){b("Please select both dates.");return}b(""),L({startDate:h(m).format("YYYY-MM-DD"),endDate:h(g).format("YYYY-MM-DD")}).unwrap().then(e=>{e.code===200?D(e.list||[]):(D([]),b(e.message))}).catch(()=>b("Something went wrong"))},S=Y.useMemo(()=>{const e={};return w.forEach(o=>{const s=[];(o.diagnosisCategoryDetails||[]).forEach(a=>{(a.diagnosisTestDetailsList||[]).forEach(d=>s.push(d))}),(o.diagnosisTestDetailsList||[]).forEach(a=>s.push(a)),s.forEach(a=>{const d=a.name||a.testCode||"Unknown";e[d]||(e[d]={name:d,code:a.testCode||"-",count:0,totalAmount:0}),e[d].count++,e[d].totalAmount+=Number(a.amount||0)})}),Object.values(e).sort((o,s)=>s.totalAmount-o.totalAmount)},[w]),i=Y.useMemo(()=>{if(!T.trim())return S;const e=T.trim().toLowerCase();return S.filter(o=>o.name.toLowerCase().includes(e)||o.code.toLowerCase().includes(e))},[S,T]),y=i.reduce((e,o)=>e+o.count,0),z=i.reduce((e,o)=>e+o.totalAmount,0),B=i.slice(j*p,j*p+p),u=e=>`₹ ${Number(e||0).toFixed(2)}`,N=()=>{const e=new ee,o=e.internal.pageSize.getWidth();e.setFillColor(29,78,216),e.rect(0,0,o,28,"F"),e.setFont("helvetica","bold"),e.setFontSize(14),e.setTextColor(255,255,255),e.text("TEST-WISE REVENUE REPORT",14,18),e.setFontSize(9),e.setFont("helvetica","normal"),e.text(`${h(m).format("DD MMM YYYY")} - ${h(g).format("DD MMM YYYY")}`,o-14,18,{align:"right"}),e.autoTable({startY:34,head:[["#","Test Name","Code","Times Ordered","Total Revenue","Avg Price"]],body:i.map((s,a)=>[a+1,s.name,s.code,s.count,u(s.totalAmount),u(s.count>0?s.totalAmount/s.count:0)]),foot:[["","TOTAL","",y,u(z),""]],headStyles:{fillColor:[29,78,216],fontSize:8},bodyStyles:{fontSize:8},footStyles:{fillColor:[248,250,252],textColor:[15,23,42],fontStyle:"bold",fontSize:8},theme:"grid",styles:{lineColor:[226,232,240],lineWidth:.3},margin:{left:14,right:14}}),e.save(`Test_Revenue_Report_${h(m).format("YYYY-MM-DD")}.pdf`)},V=()=>{const o=[["#","Test Name","Code","Times Ordered","Total Revenue","Avg Price"].join(",")];i.forEach((s,a)=>o.push([a+1,`"${s.name}"`,s.code,s.count,s.totalAmount.toFixed(2),(s.count>0?s.totalAmount/s.count:0).toFixed(2)].join(","))),te.saveAs(new Blob([o.join(`
`)],{type:"text/csv;charset=utf-8"}),`Test_Revenue_Report_${h(m).format("YYYY-MM-DD")}.csv`)};return t.jsxs(v,{sx:{px:{xs:1.5,sm:2.5},py:1.5},children:[t.jsxs(v,{sx:{display:"flex",flexWrap:"wrap",gap:1.5,mb:2,alignItems:"center"},children:[t.jsx(M,{dateAdapter:F,children:t.jsx(E,{label:"From",value:m,onChange:W,slotProps:{textField:{size:"small",sx:{width:155,"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),t.jsx(M,{dateAdapter:F,children:t.jsx(E,{label:"To",value:g,onChange:I,slotProps:{textField:{size:"small",sx:{width:155,"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}}}}})}),t.jsx(R,{variant:"contained",disableElevation:!0,startIcon:t.jsx(k,{}),onClick:$,sx:{textTransform:"none",borderRadius:"8px",px:2,fontSize:"0.8125rem",fontWeight:600,backgroundColor:"#1d4ed8","&:hover":{backgroundColor:"#1e40af"}},children:"Search"}),i.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(R,{variant:"outlined",size:"small",startIcon:t.jsx(Z,{}),onClick:N,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.8125rem",fontWeight:600},children:"PDF"}),t.jsx(R,{variant:"outlined",size:"small",startIcon:t.jsx(X,{}),onClick:V,sx:{textTransform:"none",borderRadius:"8px",fontSize:"0.8125rem",fontWeight:600},children:"CSV"})]}),t.jsx(G,{label:`${i.length} tests`,size:"small",sx:{backgroundColor:l?"rgba(255,255,255,0.08)":"#f1f5f9",color:l?"#e2e8f0":"#475569",fontWeight:600,fontSize:"0.7rem",borderRadius:"6px"}})]}),S.length>0&&t.jsx(v,{sx:{mb:2},children:t.jsx(J,{size:"small",placeholder:"Filter tests...",value:T,onChange:e=>{_(e.target.value),C(0)},sx:{width:{xs:"100%",sm:250},"& .MuiOutlinedInput-root":{borderRadius:"8px",fontSize:"0.8125rem"}},InputProps:{startAdornment:t.jsx(oe,{position:"start",children:t.jsx(k,{sx:{fontSize:16,color:"#94a3b8"}})})}})}),P&&t.jsx(K,{sx:{color:"#ef4444",fontSize:"0.8125rem",mb:2},children:P}),i.length>0&&t.jsxs(se,{component:Q,variant:"outlined",sx:{borderRadius:2,borderColor:l?"rgba(255,255,255,0.08)":"#e2e8f0",boxShadow:"none"},children:[t.jsxs(re,{size:"small",children:[t.jsx(ae,{children:t.jsxs(A,{sx:{backgroundColor:l?"rgba(255,255,255,0.04)":"#f8fafc"},children:[t.jsx(r,{sx:f,children:"#"}),t.jsx(r,{sx:f,children:"Test Name"}),t.jsx(r,{sx:f,children:"Code"}),t.jsx(r,{sx:{...f,textAlign:"right"},children:"Times Ordered"}),t.jsx(r,{sx:{...f,textAlign:"right"},children:"Total Revenue"}),t.jsx(r,{sx:{...f,textAlign:"right"},children:"Avg Price"})]})}),t.jsxs(ne,{children:[B.map((e,o)=>t.jsxs(A,{hover:!0,sx:{"&:hover":{backgroundColor:l?"rgba(255,255,255,0.03)":"#fafbfe"}},children:[t.jsx(r,{sx:n,children:j*p+o+1}),t.jsx(r,{sx:{...n,fontWeight:500},children:e.name}),t.jsx(r,{sx:{...n,color:"#64748b"},children:e.code}),t.jsx(r,{sx:{...n,textAlign:"right"},children:e.count}),t.jsx(r,{sx:{...n,textAlign:"right",fontWeight:600,color:"#059669"},children:u(e.totalAmount)}),t.jsx(r,{sx:{...n,textAlign:"right",color:"#64748b"},children:u(e.count>0?e.totalAmount/e.count:0)})]},e.name)),t.jsxs(A,{sx:{backgroundColor:l?"rgba(255,255,255,0.04)":"#f8fafc"},children:[t.jsx(r,{sx:{...n,fontWeight:700}}),t.jsx(r,{sx:{...n,fontWeight:700},children:"TOTAL"}),t.jsx(r,{sx:n}),t.jsx(r,{sx:{...n,textAlign:"right",fontWeight:700},children:y}),t.jsx(r,{sx:{...n,textAlign:"right",fontWeight:700,color:"#059669"},children:u(z)}),t.jsx(r,{sx:n})]})]})]}),t.jsx(ie,{component:"div",count:i.length,page:j,onPageChange:(e,o)=>C(o),rowsPerPage:p,onRowsPerPageChange:e=>{O(parseInt(e.target.value,10)),C(0)},rowsPerPageOptions:[5,10,25],sx:{borderTop:`1px solid ${l?"rgba(255,255,255,0.06)":"#f1f5f9"}`,"& .MuiTablePagination-selectLabel, & .MuiTablePagination-displayedRows":{fontSize:"0.75rem"}}})]})]})}export{Pe as default};
