import{j as e,M as w,S as C,c as _,W as M}from"./vendor-mui-CBBEb17G.js";import{a as d}from"./vendor-react-BBazpZul.js";import{e as O,fH as $,aE as X,J as V,al as W,aX as J,z as H,gE as K,aO as Q,v as Z,e7 as ee,by as N,r as B,aP as T,bE as te,x as ae,at as se,dD as F,c4 as oe,et as re,bx as ne,c$ as le,ao as U,I as z}from"./index-IP_FWtso.js";import"./vendor-utils-BveVE6Uf.js";import{B as ie}from"./index-BkhbTDKf.js";import{T as ce}from"./index-Dz6vPtCj.js";import"./vendor-charts-tGnAgELZ.js";const G=d.createContext(void 0),de=({children:r})=>{const{getRooms:l,addRoom:i,updateRoom:m,deleteRoom:p,getRoomTypes:a}=X(),{GetDepartmentsReq:t}=$(),{clinicId:h,officeId:R}=O(o=>o.doctorData),[v,I]=d.useState(!1),[f,g]=d.useState(!1),[u,A]=d.useState(!1),[q,s]=d.useState([]),[c,x]=d.useState(null),[b,j]=d.useState(null),[D,k]=d.useState([]);d.useEffect(()=>{v||(I(!0),L(),y(),P()),I(!1)},[]);const L=async()=>{const{data:o}=await t({ClinicId:h,OfficeId:R});if(!o)return;const n=o==null?void 0:o.map(S=>({label:S==null?void 0:S.title,value:S==null?void 0:S.id}));j(n)},y=async(o=void 0)=>{const{data:n}=await l({clinicId:h,officeId:R,departmentId:o});n&&s(n)},P=async()=>{const{data:o}=await a();o&&k(o.map(n=>({label:n.title,value:n.id.toString()})))},Y={types:D,fetchLoading:v,actionLoading:f,roomsList:q,addRoom:async o=>{try{g(!0);const{message:n}=await i(o);V.success(n)}finally{g(!1)}},updateRoom:async o=>{try{g(!0);const{message:n}=await m(o);V.success(n)}finally{g(!1)}},getRooms:y,selectedRow:c,departmentList:b,serachRooms:o=>{if(!o&&!q.length)return y();const n=q.filter(S=>S.name.includes(o));return s(n)},setSelectedRow:x,editMode:u,setEditMode:A,deleteRoom:async o=>{try{g(!0);const{message:n}=await p(o);V.success(n)}finally{g(!1)}},getDepartments:L};return e.jsx(G.Provider,{value:Y,children:r})},E=()=>d.useContext(G),ue=W(w)`
  box-shadow: 0 3px 20px rgb(0 0 0 / 4%);
  padding: 10px 20px;

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

  .btc-icons {
    background: rgba(51, 83, 178, 0.04);
    min-width: 49px;
    margin: 0 5px;
  }
`;const me=()=>{const{roomsList:r,fetchLoading:l,setSelectedRow:i}=E(),m=a=>{i(a)},p=[{title:"کد",dataIndex:"customId",key:"customId",width:100,render:(a,t,h)=>a?H(a):"-"},{title:"دپارتمان",dataIndex:"departmentName",key:"departmentName",width:250,render:a=>a?K(a):"-"},{title:"نام اتاق",dataIndex:"name",key:"name",width:200,render:a=>a?K(a):"-"},{title:"نوع اتاق",dataIndex:"typeName",key:"typeName",width:150},{title:"شماره اتاق",dataIndex:"roomNumber",key:"roomNumber",width:100,render:a=>a?H(a):"---"},{title:"شماره شروع صف",dataIndex:"queueStartNumber",key:"queueStartNumber",width:100,render:a=>a?H(a):"---"},{title:"آدرس نمایشگر نوبت",dataIndex:"queueDisplayIp",key:"queueDisplayIp",width:200,render:a=>a||"-"},{title:"آدرس سیستم فراخوان",dataIndex:"callServiceHost",key:"callServiceHost",width:200,render:a=>a||"-"}];return e.jsx(J,{loading:l,rowKey:"id",columns:p||[],data:r||[],onClick:a=>m(a),boxProps:{sx:{height:"70vh"}}})},pe=Array.from({length:10}).map((r,l)=>({label:H(`${l}001`),value:`${l}001`})),xe=({setOpen:r})=>{const{addRoom:l,types:i,fetchLoading:m,updateRoom:p,departmentList:a,selectedRow:t,setSelectedRow:h,getRooms:R,editMode:v,actionLoading:I}=E(),{control:f,handleSubmit:g,formState:{errors:u},reset:A}=Q({defaultValues:{name:(t==null?void 0:t.name)??"",queueDisplayIp:(t==null?void 0:t.queueDisplayIp)??"",callServiceHost:(t==null?void 0:t.callServiceHost)??"",department:t?{label:t.departmentName,value:t.departmentId}:null,type:t?{label:t.typeName,value:t.type}:null,roomNumber:(t==null?void 0:t.roomNumber)??0,queueStartNumber:t==null?void 0:t.queueStartNumber}}),q=async s=>{const{name:c,queueDisplayIp:x,callServiceHost:b,department:j,type:D,roomNumber:k,queueStartNumber:L}=s;if(!(!j||!D||!c||!k))try{const y={name:c,queueDisplayIp:x||void 0,callServiceHost:b||void 0,departmentId:+j.value,type:+D.value,roomNumber:k||void 0,queueStartNumber:L};if(v){const P={id:t==null?void 0:t.id,...y};await p(P)}else await l(y)}catch(y){console.log(y)}finally{h(null),r(!1),A(),R()}};return e.jsx(Z,{title:v?"ویرایش اتاق":"افزودن اتاق",maxWidth:"xs",onClose:()=>r(!1),children:m?e.jsx(C,{height:250,className:"!flex !items-center !justify-center",children:e.jsx(ee,{})}):e.jsxs(_,{children:[e.jsxs(C,{component:"form",paddingY:1.5,gap:1.5,children:[e.jsx(N,{name:"department",control:f,rules:{required:!0},render:({field:s})=>{var c,x;return e.jsx(B,{...s,label:"انتخاب دپارتمان",defaultValue:t?t==null?void 0:t.departmentId:(c=a==null?void 0:a[0])==null?void 0:c.value,items:a,value:((x=s.value)==null?void 0:x.value)??"",onchange:b=>s.onChange(a.find(j=>j.value===Number(b))),validation:{required:!0},error:!!u.department,required:!0})}}),e.jsx(N,{name:"name",control:f,rules:{required:!0,minLength:1,maxLength:150},render:({field:s})=>e.jsx(T,{...s,label:"نام",error:!!u.name,required:!0})}),e.jsx(N,{name:"queueDisplayIp",control:f,render:({field:s})=>e.jsx(T,{...s,label:"آدرس نمایشگر نوبت",placeholder:"http://1.1.1.1"})}),e.jsx(N,{name:"callServiceHost",control:f,render:({field:s})=>e.jsx(T,{...s,label:"آدرس سیستم فراخوان",placeholder:"http://1.1.1.1"})}),e.jsx(N,{name:"type",control:f,rules:{required:!0},render:({field:s})=>{var c,x;return e.jsx(B,{...s,label:"نوع اتاق",defaultValue:t?t==null?void 0:t.type:(c=i==null?void 0:i[0])==null?void 0:c.value,items:i,value:((x=s.value)==null?void 0:x.value)??"",onchange:b=>s.onChange(i.find(j=>j.value===b)),error:!!u.type,required:!0})}}),e.jsx(N,{name:"roomNumber",control:f,render:({field:s})=>e.jsx(te,{...s,minValue:0,label:"شماره اتاق",error:!!(u!=null&&u.roomNumber)})}),e.jsx(N,{name:"queueStartNumber",control:f,render:({field:s})=>e.jsx(B,{...s,label:"شماره شروع صف",items:pe,onchange:c=>s.onChange(c),error:!!(u!=null&&u.roomNumber)})})]}),e.jsx(ae,{disabled:I,loading:I,onClose:()=>r(!1),onSubmit:g(q),submitlabel:"ثبت"})]})})},he=()=>{const{selectedRow:r,setSelectedRow:l,getRooms:i,deleteRoom:m,setEditMode:p}=E(),a=se(),[t,h]=d.useState(!1),R=()=>{l(null),p(!1),h(!0)},v=()=>{r&&(p(!0),h(!0))},I=()=>{r&&a({content:"آیا از حذف این اتاق مطمئن هستید؟"}).then(async()=>{r&&await m(r==null?void 0:r.id),i(),l(null)}).catch(()=>{})};return e.jsxs(e.Fragment,{children:[e.jsxs(C,{direction:"row",paddingY:1,spacing:1,children:[e.jsx(M,{title:"افزودن",placement:"top",children:e.jsx(F,{onClick:R,children:e.jsx(oe,{fontSize:"large",color:"success"})})}),e.jsx(M,{title:"ویرایش",placement:"top",children:e.jsx(F,{onClick:v,children:e.jsx(re,{fontSize:"large",color:r?"primary":"disabled"})})}),e.jsx(M,{title:"حذف",placement:"top",children:e.jsx(F,{onClick:I,children:e.jsx(ne,{fontSize:"large",color:r?"error":"disabled"})})})]}),t&&e.jsx(xe,{setOpen:()=>h(!1)})]})},fe=()=>{const{userType:r}=O(t=>t.user),{serachRooms:l}=E(),[i,m]=d.useState(""),p=()=>{l(i)},a=()=>{m(""),l("")};return e.jsxs(C,{className:"h-full overflow-y-auto p-2 pb-10 border-l",spacing:1,children:[e.jsx(ce,{className:+r===le.accountant?"!bg-[#b0d8e7]":"",children:"نام اتاق"}),e.jsx(T,{label:"اتاق ...",value:i,onChange:m}),e.jsxs(C,{component:"form",direction:"row",justifyContent:"center",gap:1,children:[e.jsx(U,{fullWidth:!0,startIcon:e.jsx(z.SearchIcon,{}),onClick:p,children:"جستجو"}),e.jsx(U,{fullWidth:!0,startIcon:e.jsx(z.RefreshIcon,{}),onClick:a,children:"بازنشانی"})]})]})},ge=()=>e.jsxs(ue,{className:"!px-4 !py-2",children:[e.jsx(ie,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"اتاق ها"}),e.jsxs(w,{container:!0,xs:12,spacing:1,className:"!h-full",children:[e.jsx(w,{item:!0,xs:12,sm:2,children:e.jsx(fe,{})}),e.jsxs(w,{item:!0,xs:12,sm:10,spacing:1,children:[e.jsx(he,{}),e.jsx(me,{})]})]})]}),ke=()=>e.jsx(de,{children:e.jsx(ge,{})});export{ke as default};
