import{j as e,S as r,aW as F,aX as K,aY as U,c as X,M as g}from"./vendor-mui-CBBEb17G.js";import{e as N,e6 as E,aX as Y,z as q,aZ as G,at as Z,Z as _,aO as $,n as C,dD as y,c4 as J,et as Q,bx as ee,v as se,aP as B,w as te,x as ae,al as P,c$ as ne,ao as k,I as R}from"./index-IP_FWtso.js";import{a as n}from"./vendor-react-BBazpZul.js";import"./vendor-utils-BveVE6Uf.js";import{B as ie}from"./index-BkhbTDKf.js";import{T as oe}from"./index-Dz6vPtCj.js";import"./vendor-charts-tGnAgELZ.js";const T=n.createContext(void 0),re=({children:c})=>{const{getDiseaseAsync:a}=E(),{clinicId:s,officeId:o}=N(d=>d.doctorData),[l,t]=n.useState(!1),[i,j]=n.useState([]),[u,f]=n.useState(null),x=async d=>{t(!0);const{data:b}=await a(d);j(b),t(!1)};n.useEffect(()=>{x()},[]);const h={loading:l,DiseaseList:i,getData:x,search:d=>{x(d)},rowSelected:u,setRowSelected:f};return e.jsx(T.Provider,{value:h,children:c})},I=()=>n.useContext(T),ce=()=>{const{DiseaseList:c,loading:a,setRowSelected:s}=I(),o=[{title:"ردیف",dataIndex:"id",key:"id",width:50,render:t=>q(t)},{title:"عنوان",dataIndex:"title",key:"title",width:400},{title:"زیر مجموعه",dataIndex:"child",key:"child",width:200,render:t=>e.jsxs(F,{className:"!rounded-3xl !py-0 !m-0 ma",children:[e.jsx(K,{expandIcon:e.jsx(G,{}),classes:{root:"!min-h-[30px] !max-h-[30px]"},children:`${t.length} مورد`}),t.map(i=>e.jsx(U,{className:"mx-2 my-1 !py-1 rounded-3xl hover:bg-green-400 ",onClick:()=>s(i),children:i.title},i.id))]})}],l=t=>{s(t)};return e.jsx(r,{className:"!h-[75vh]",children:e.jsx(Y,{loading:a,rowKey:"id",columns:o||[],data:c||[],onClick:t=>l(t)})})},le=()=>{const c=Z(),{getData:a,rowSelected:s,setRowSelected:o,DiseaseList:l}=I(),{addDiseaseAsync:t,updateDiseaseAsync:i,deleteDiseaseAsync:j}=E(),{isInRole:u}=_(),{register:f,handleSubmit:x,formState:{errors:v},reset:h,getValues:d,setValue:b}=$(),[M,m]=n.useState(!1),[S,w]=n.useState(!1),[D,H]=n.useState(null),L=()=>{w(!1),m(!0),h()},V=()=>{s&&(w(!0),m(!0),b("name",s==null?void 0:s.title))},z=()=>{s&&c({content:"آیا از حذف این آیتم مطمئن هستید؟"}).then(async()=>{await j(s.id),a(),o(null)}).catch(()=>{})},O=async p=>{const{name:W}=p,A={name:String(W),parentId:D?+D.value:void 0};try{S?(await i({...A,id:s==null?void 0:s.id}),a(),o(null)):await t(A),m(!1),a(),h()}catch{}};return e.jsxs(e.Fragment,{children:[e.jsxs(r,{direction:"row",paddingY:1,spacing:1,children:[u(void 0,[C.AddDisease])&&e.jsx(y,{onClick:L,children:e.jsx(J,{fontSize:"large",color:"success"})}),u(void 0,[C.EditDisease])&&e.jsx(y,{onClick:V,children:e.jsx(Q,{fontSize:"large",color:s?"primary":"disabled"})}),u(void 0,[C.DeleteDisease])&&e.jsx(y,{onClick:z,children:e.jsx(ee,{fontSize:"large",color:s?"error":"disabled"})})]}),M&&e.jsxs(se,{title:S?"ویرایش بیماری":"افزودن بیماری",maxWidth:"xs",onClose:()=>m(!1),children:[e.jsx(X,{children:e.jsxs(r,{component:"form",marginBottom:0,paddingTop:1.5,spacing:1.5,alignItems:"center",children:[e.jsx(r,{width:"100%",children:e.jsx(B,{label:"نام بیماری",name:"name",register:f,validation:{required:!0},error:!!v.title,required:!0})}),e.jsx(r,{width:"100%",children:e.jsx(te,{label:"انتخاب سرشاخه",selectOption:l.map(p=>({label:p.title,value:p.id.toString()})),value:D,onChange:H})})]})}),e.jsx(ae,{onClose:()=>m(!1),onSubmit:x(O),submitlabel:S?"ثبت":"افزودن",className:"mb-4"})]})]})},de=P(g)`
  box-shadow: 0 3px 20px rgb(0 0 0 / 4%);
  background-color: rgb(255, 255, 255);
  padding: 10px 20px 10px;
  min-height: 100vh;

  .MuiDataGrid-cell {
    cursor: pointer !important;
  }
`;P(r)`
  margin-bottom: 0;

  .btc-icons {
    background: rgba(51, 83, 178, 0.04);
    min-width: 49px;
    margin: 0 5px;
  }
`;const ue=()=>{const{userType:c}=N(i=>i.user),{search:a}=I(),[s,o]=n.useState(""),l=()=>{a(s)},t=()=>{o(""),a("")};return e.jsxs(r,{className:"h-full overflow-y-auto p-2 pb-10 border-l",spacing:1,children:[e.jsx(oe,{className:+c===ne.accountant?"!bg-[#b0d8e7]":"",children:"نام بیماری"}),e.jsx(B,{label:"بیماری ...",value:s,onChange:o}),e.jsxs(r,{component:"form",direction:"row",justifyContent:"center",gap:1,children:[e.jsx(k,{fullWidth:!0,startIcon:e.jsx(R.SearchIcon,{}),onClick:l,children:"جستجو"}),e.jsx(k,{fullWidth:!0,startIcon:e.jsx(R.RefreshIcon,{}),onClick:t,children:"بازنشانی"})]})]})},xe=()=>e.jsxs(de,{className:"!px-4 !py-2",children:[e.jsx(ie,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"بیماری خاص"}),e.jsxs(g,{container:!0,xs:12,spacing:1,className:"!h-full",children:[e.jsx(g,{item:!0,xs:12,sm:2,children:e.jsx(ue,{})}),e.jsxs(g,{item:!0,xs:12,sm:10,spacing:1,children:[e.jsx(le,{}),e.jsx(ce,{})]})]})]}),De=()=>e.jsx(re,{children:e.jsx(xe,{})});export{De as default};
