import{j as t,S as x,c as V,M as b}from"./vendor-mui-CBBEb17G.js";import{S as z}from"./index-BW4CgsKJ.js";import{a}from"./vendor-react-BBazpZul.js";import{e as y,aX as K,gE as O,at as U,aO as W,Z as X,n as G,dD as I,I as m,v as Y,aP as D,x as _,c$ as q,ao as E}from"./index-DdWwwZXu.js";import"./vendor-utils-BveVE6Uf.js";import{c as k}from"./index-CWIrdky3.js";import{B as Z}from"./index-DQbmBtLN.js";import{T as $}from"./index-DwtyCRac.js";import"./vendor-charts-tGnAgELZ.js";const T=a.createContext(void 0),J=({children:e})=>{const{getContacGroupsAsync:s}=k(),{clinicId:o,officeId:r}=y(c=>c.doctorData),[n,l]=a.useState(!1),[d,f]=a.useState([]),[j,g]=a.useState(null),u=async c=>{l(!0);const{data:C}=await s(o,r,c);f(C),l(!1)};a.useEffect(()=>{u()},[]);const h={loading:n,contactsGroupsList:d,getData:u,search:c=>{u(c)},rowSelected:j,setRowSelected:g};return t.jsx(T.Provider,{value:h,children:e})},R=()=>a.useContext(T),Q=[{title:"عنوان",dataIndex:"title",key:"title",render:(e,s,o)=>O(e)}],tt=()=>{const{contactsGroupsList:e,loading:s,setRowSelected:o}=R(),r=n=>{o(n)};return t.jsx(K,{loading:s,rowKey:"id",columns:Q||[],data:e||[],onClick:n=>r(n),boxProps:{height:"75vh"}})},et=()=>{const{rowSelected:e,getData:s,setRowSelected:o}=R(),{clinicId:r,officeId:n}=y(i=>i.doctorData),l=U(),{deleteContactGroupAsync:d,addContactGroupAsync:f,updateContactGroupAsync:j}=k(),{register:g,handleSubmit:u,formState:{errors:v},reset:h,setValue:c}=W(),[C,p]=a.useState(!1),[S,w]=a.useState(!1),{isInRole:N}=X(),P=()=>{w(!1),p(!0),h()},B=()=>{e&&(w(!0),p(!0),c("title",e==null?void 0:e.title))},F=()=>{e&&l({content:"آیا از حذف این آیتم مطمئن هستید؟"}).then(async()=>{await d(e.id),s(),o(null)}).catch(()=>{})},H=async i=>{const{title:M}=i,A={title:String(M),clinicId:r,officeId:n};try{S?(await j({...A,id:e==null?void 0:e.id}),s(),o(null)):await f(A),p(!1),s(),h()}catch{}},L=[{item:t.jsx(I,{onClick:P,children:t.jsx(m.AddIcon,{fontSize:"large",color:"success"})},1),expectedRoles:G.AddContactGroup},{item:t.jsx(I,{onClick:B,children:t.jsx(m.EditIcon,{fontSize:"large",color:e?"primary":"disabled"})},2),expectedRoles:G.EditContactGroup},{item:t.jsx(I,{onClick:F,children:t.jsx(m.DeleteIcon,{fontSize:"large",color:e?"error":"disabled"})},3),expectedRoles:G.EditContactGroup}];return t.jsxs(t.Fragment,{children:[t.jsx(x,{direction:"row",paddingY:1,spacing:1,children:L.filter(i=>N(void 0,[i.expectedRoles])===!0).map(i=>i.item)}),C&&t.jsxs(Y,{title:S?"ویرایش گروه مخاطبین":"افزودن گروه مخاطبین",maxWidth:"xs",dialogProps:{classes:{paper:"!pb-3"}},onClose:()=>p(!1),children:[t.jsx(V,{children:t.jsx(x,{component:"form",paddingX:0,marginBottom:0,paddingTop:1.5,alignItems:"center",children:t.jsx(x,{width:"100%",children:t.jsx(D,{label:"عنوان",name:"title",register:g,validation:{required:!0},error:!!v.title})})})}),t.jsx(_,{onClose:()=>p(!1),onSubmit:u(H),submitlabel:S?"ثبت":"افزودن"})]})]})},st=()=>{const{userType:e}=y(d=>d.user),{search:s}=R(),[o,r]=a.useState(""),n=()=>{s(o)},l=()=>{r(""),s("")};return t.jsxs(x,{className:"h-full overflow-y-auto p-2 pb-10 border-l",spacing:1,children:[t.jsx($,{className:+e===q.accountant?"!bg-[#b0d8e7]":"",children:"نام گروه"}),t.jsx(D,{label:"گروه ...",value:o,onChange:r}),t.jsxs(x,{component:"form",direction:"row",justifyContent:"center",gap:1,children:[t.jsx(E,{fullWidth:!0,startIcon:t.jsx(m.SearchIcon,{}),onClick:n,children:"جستجو"}),t.jsx(E,{fullWidth:!0,startIcon:t.jsx(m.RefreshIcon,{}),onClick:l,children:"بازنشانی"})]})]})},ot=()=>t.jsxs(z,{className:"!px-4 !py-2",children:[t.jsx(Z,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"گروه مخاطبین"}),t.jsxs(b,{container:!0,xs:12,spacing:1,className:"!h-full",children:[t.jsx(b,{item:!0,xs:12,sm:2,children:t.jsx(st,{})}),t.jsxs(b,{item:!0,xs:12,sm:10,spacing:1,children:[t.jsx(et,{}),t.jsx(tt,{})]})]})]}),mt=()=>t.jsx(J,{children:t.jsx(ot,{})});export{mt as default};
