import{j as e,S,M as I}from"./vendor-mui-CBBEb17G.js";import{S as A}from"./index-CDArk_1r.js";import{e as y,bA as D,at as B,dD as w,I as x,bH as L,aX as E,z as T,aP as P,ao as k}from"./index-DdWwwZXu.js";import{a as s}from"./vendor-react-BBazpZul.js";import"./vendor-utils-BveVE6Uf.js";import{T as z}from"./index-DwtyCRac.js";import{B as H}from"./index-DQbmBtLN.js";import"./vendor-charts-tGnAgELZ.js";const N=s.createContext(void 0),M=({children:l})=>{const{getReagentAsync:t}=D(),{clinicId:a,officeId:c}=y(p=>p.doctorData),[r,i]=s.useState(!1),[o,n]=s.useState([]),[d,m]=s.useState([]),[h,f]=s.useState(null),[R,C]=s.useState(null),g=async p=>{i(!0),f(null);const{data:u}=await t({clinicId:a,officeId:c});u&&n(u),i(!1)};s.useEffect(()=>{g()},[]),s.useEffect(()=>{m(o)},[o]);const v={loading:r,reagentList:o,reagentDataList:d,search:p=>{m(o.filter(u=>`${u.firstName} ${u.lastName}`.includes(p)))},rowSelected:h,setRowSelected:f,getReagentData:g,selectedItem:R,setSelectedItem:C};return e.jsx(N.Provider,{value:v,children:l})},b=()=>s.useContext(N),K=()=>{const{getReagentData:l,rowSelected:t,setRowSelected:a}=b(),{deleteRegentAsync:c}=D(),r=B(),{clinicId:i,officeId:o}=y(j=>j.doctorData),[n,d]=s.useState(!1),[m,h]=s.useState(!1),f=()=>{a(null),h(!1),d(!0)},R=()=>{t&&(h(!0),d(!0))},C=()=>{t&&r({content:"آیا از حذف این آیتم مطمئن هستید؟"}).then(async()=>{await c(t.id),l(),a(null)}).catch(()=>{})},g=j=>{d(!1),a(null),j&&l()};return e.jsxs(e.Fragment,{children:[e.jsxs(S,{direction:"row",paddingY:1,spacing:1,children:[e.jsx(w,{onClick:f,children:e.jsx(x.AddIcon,{fontSize:"large",color:"success"})}),e.jsx(w,{onClick:R,children:e.jsx(x.EditIcon,{fontSize:"large",color:t?"primary":"disabled"})}),e.jsx(w,{onClick:C,children:e.jsx(x.DeleteIcon,{fontSize:"large",color:t?"error":"disabled"})})]}),n&&e.jsx(L,{editMode:m,selectedItem:t,onClose:g})]})},V=()=>{const{reagentList:l,loading:t,setRowSelected:a,reagentDataList:c,setSelectedItem:r}=b(),i=n=>{a(n)},o=[{title:"کد",dataIndex:"id",key:"id",width:40,render:n=>T(n)},{title:"نام",dataIndex:"firstName",key:"firstName",width:100},{title:"نام خانوادگی",dataIndex:"lastName",key:"lastName",width:150}];return e.jsx(S,{className:"h-[78dvh]",children:e.jsx(E,{loading:t,rowKey:"id",columns:o||[],data:c||[],onClick:n=>i(n)})})},F=()=>{const{userType:l}=y(n=>n.user),{getReagentData:t,search:a}=b(),[c,r]=s.useState(""),i=()=>{a(c)},o=()=>{r(""),t()};return e.jsxs(S,{className:"h-full overflow-y-auto p-2 pb-10 border-l",spacing:1,children:[e.jsx(z,{children:"نام معرف"}),e.jsx(P,{label:"معرف ...",value:c,onChange:r}),e.jsxs(S,{component:"form",direction:"row",justifyContent:"center",gap:1,children:[e.jsx(k,{fullWidth:!0,startIcon:e.jsx(x.SearchIcon,{}),onClick:i,children:"جستجو"}),e.jsx(k,{fullWidth:!0,startIcon:e.jsx(x.RefreshIcon,{}),onClick:o,children:"بازنشانی"})]})]})},O=()=>e.jsxs(I,{container:!0,xs:12,spacing:1,className:"!h-full",children:[e.jsx(I,{item:!0,xs:12,sm:2,children:e.jsx(F,{})}),e.jsxs(I,{item:!0,xs:12,sm:10,spacing:1,children:[e.jsx(K,{}),e.jsx(V,{})]})]}),Q=()=>e.jsxs(A,{className:"!space-y-3 py-2 px-4 bg-white",children:[e.jsx(H,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"معرف"}),e.jsx(M,{children:e.jsx(O,{})})]});export{Q as default};
