import{j as e,c as D,S as p,W as A}from"./vendor-mui-CBBEb17G.js";import{at as M,J as f,aO as I,v as E,by as w,aP as v,bE as y,x as P,dD as F,I as j,dY as W,aX as K}from"./index-IP_FWtso.js";import{a as h}from"./vendor-react-BBazpZul.js";import{u as q}from"./index-UwEaYvCN.js";import"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";const z={tabValue:"1",data:null,selectedRow:null},N=h.createContext(void 0),O=({children:s})=>{const n=M(),{loading:d,GetMedicalTestsAsync:i,AddMedicalTestAsync:l,EditMedicalTestAsync:c,DeleteMedicalTestAsync:r}=q(),[a,o]=h.useState(z),t=async(x="",b=1,T=50)=>{const{data:R}=await i({PageNumber:b,PageSize:T,Name:x,FilterCenter:a.tabValue!=="1"});o(k=>({...k,data:R}))},g=async x=>{const{message:b}=await l(x);f.success(b),t()},u=async x=>{if(!a.selectedRow){f.warning("موردی انتخاب نشده است");return}const{message:b}=await c({...x,id:a.selectedRow.id});f.success(b),t()},m=()=>{if(!a.selectedRow){f.warning("موردی انتخاب نشده است");return}n({content:"آیا از حذف این آزمایش اطمینان دارید؟"}).then(async()=>{const{message:x}=await r(a.selectedRow.id);f.success(x),t()}).catch(()=>{})};h.useEffect(()=>{a.tabValue&&t()},[a.tabValue]);const S={state:a,setState:o,loading:d,handlers:{fetchData:t,handleAdd:g,handleEdit:u,handleDelete:m}},V=h.useMemo(()=>S,[S]);return e.jsx(N.Provider,{value:V,children:s})},C=()=>h.useContext(N),U=({onClose:s})=>{const{state:n,loading:d,handlers:i}=C(),{control:l,handleSubmit:c,reset:r,formState:{errors:a}}=I({defaultValues:{...n.selectedRow}}),o=async t=>{if(t){if(n.selectedRow){await i.handleEdit(t),s();return}await i.handleAdd(t),s()}};return e.jsxs(E,{onClose:s,title:n.selectedRow?`ویرایش اطلاعات ${n.selectedRow.title}`:"افزودن آزمایش جدید",maxWidth:"sm",isFixWidth:!0,children:[e.jsx(D,{className:"m-1 !p-2",children:e.jsxs(p,{component:"form",spacing:2,children:[e.jsx(w,{name:"title",control:l,rules:{required:!0},render:({field:t})=>e.jsx(v,{label:"عنوان",fullWidth:!0,error:!!a.title,...t})}),e.jsx(w,{name:"minNormalValue",control:l,rules:{required:!0},render:({field:t})=>e.jsx(y,{label:"حد نرمال پایین",fullWidth:!0,error:!!a.minNormalValue,...t})}),e.jsx(w,{name:"maxNormalValue",control:l,rules:{required:!0},render:({field:t})=>e.jsx(y,{label:"حد نرمال بالا",fullWidth:!0,error:!!a.maxNormalValue,...t})})]})}),e.jsx(P,{loading:d,onClose:s,onSubmit:c(o)})]})},B=()=>{const{state:s,setState:n,loading:d,handlers:i}=C(),l=!s.selectedRow||d,[c,r]=h.useState(!1),a=()=>{r(!1),n(t=>({...t,selectedRow:null}))},o=[{id:1,title:"افزودن",icons:e.jsx(j.AddIcon,{color:"success"}),onClick:()=>r(!0),disabled:!1},{id:2,title:"ویرایش",icons:e.jsx(j.EditIcon,{color:l?"disabled":"primary"}),onClick:()=>r(!0),disabled:l},{id:3,title:"حذف",icons:e.jsx(j.DeleteIcon,{color:l?"disabled":"error"}),onClick:()=>i.handleDelete(),disabled:l},{id:4,title:"تازه سازی",icons:e.jsx(j.RefreshIcon,{color:"info"}),onClick:()=>i.fetchData(),disabled:!1}];return e.jsxs(p,{direction:"row",alignItems:"center",spacing:1,p:1,px:2,children:[o.map(t=>e.jsx(A,{title:t.title,children:e.jsx(F,{onClick:()=>t.onClick(),disabled:t.disabled,children:t.icons})},t.id)),c&&e.jsx(U,{onClose:a})]})},G=()=>{var a,o,t,g;const{state:s,setState:n,loading:d,handlers:i}=C(),l=[{key:"1",title:"عمومی"},{key:"2",title:"اختصاصی"}],c=u=>{n(m=>({...m,tabValue:u}))},r=[{title:"عنوان",key:"title",dataIndex:"title",width:200},{title:"حد نرمال پایین",key:"minNormalValue",dataIndex:"minNormalValue",width:100},{title:"حد نرمال بالا",key:"maxNormalValue",dataIndex:"maxNormalValue",width:100}];return e.jsxs(p,{className:"h-[75vh]",spacing:2,children:[e.jsx(W,{tabValue:s.tabValue,data:l,handleChange:c}),e.jsx(K,{columns:r,data:((a=s.data)==null?void 0:a.list)??[],rowKey:"id",loading:d,totalCount:((o=s.data)==null?void 0:o.pagination.totalCount)??0,pageNumber:(((t=s.data)==null?void 0:t.pagination.pageNumber)??1)-1,pageSize:((g=s.data)==null?void 0:g.pagination.pageSize)??50,onPaginationLoad:(u,m)=>i.fetchData("",u+1,m),onClick:u=>n(m=>({...m,selectedRow:u}))})]})},J=()=>e.jsxs(p,{p:2,className:"h-full",children:[e.jsx(B,{}),e.jsx(G,{})]}),Z=()=>e.jsx(O,{children:e.jsx(J,{})});export{Z as default};
