import{j as e,a6 as pe,a9 as ge,M as l,S as ie,c as he,ab as be,aS as je,a8 as Se,aC as ye}from"./vendor-mui-CBBEb17G.js";import{B as Ce}from"./index-BkhbTDKf.js";import{a}from"./vendor-react-BBazpZul.js";import{fp as ve,e as V,j2 as ae,al as k,Z as De,at as we,aO as Ne,b2 as X,n as M,dD as G,c4 as ke,et as Ie,bx as Pe,v as Re,r as Te,aP as H,be as Y,bf as Z,x as Le,bl as ze,j3 as Ae,aA as _,J as ee,aX as Be,bc as Ee}from"./index-IP_FWtso.js";import"./vendor-utils-BveVE6Uf.js";import{P as Ue}from"./index-DYD6IPXt.js";import{S as Me}from"./index-D7-0uPSw.js";import"./vendor-charts-tGnAgELZ.js";const oe=a.createContext(void 0),Ge=({children:r})=>{const{GetCenterNotificationsAsync:n}=ae(),{GetCenterUsers:f}=ve(),{clinicId:p,officeId:i}=V(o=>o.doctorData),[c,j]=a.useState(!1),[S,y]=a.useState(),[g,I]=a.useState(),[P,R]=a.useState(),[h,T]=a.useState([]),b=async()=>{const{data:o}=await f(p,i);T(o)},L=async()=>{j(!0);try{const o={clinicId:p,officeId:i},{data:x}=await n(o);y(x),I(x)}catch(o){console.log(o)}finally{j(!1)}},C=o=>{const x=g==null?void 0:g.filter(v=>v.title.includes(o));y(x)};a.useEffect(()=>{b()},[]);const z={loading:c,search:C,NotificationsList:S,getData:L,rowSelected:P,setRowSelected:R,userList:h};return e.jsx(oe.Provider,{value:z,children:r})},F=()=>a.useContext(oe);k(l)`
  box-shadow: 0 3px 20px rgb(0 0 0 / 4%);
  background-color: rgb(255, 255, 255);
  height: 100%;
  padding: 10px 20px;

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

  .btc-icons {
    background: rgba(51, 83, 178, 0.04);
    min-width: 49px;
    margin: 0 5px;
  }
`;const te=k(pe)`
  .MuiFormControlLabel-label {
    font-size: 0.8rem;
  }
`,se=k(ge)`
  &.MuiRadio-root {
    padding: 2px 4px;
  }
`,He=e.jsx(Ae,{fontSize:"small"}),Ve=e.jsx(ze,{fontSize:"small"}),Fe=[{label:"اطلاع رسانی",value:0},{label:"هشدار",value:1},{label:"اخطار",value:2}],Oe=()=>{const{isInRole:r}=De(),{clinicId:n,officeId:f}=V(t=>t.doctorData),{userType:p}=V(t=>t.user),{rowSelected:i,getData:c,setRowSelected:j,userList:S}=F(),{DeleteNotification:y,AddNotification:g,GetNotificationById:I,EditNotification:P}=ae(),R=we(),{register:h,handleSubmit:T,formState:{errors:b},reset:L,setValue:C}=Ne(),[z,o]=a.useState(!1),[x,v]=a.useState(!1),[O,A]=a.useState(0),[D,w]=a.useState(!0),[N,B]=a.useState([]),[ne,K]=a.useState(!1),[q,E]=a.useState(new Date),[$,U]=a.useState(new Date),[J,re]=a.useState(X()),[Q,le]=a.useState(X()),ce=(t,s)=>{B([...s])},de=()=>{v(!1),L(),A(0),w(!0),B([]),E(new Date),U(new Date),o(!0)},ue=async()=>{var t;if(i){v(!0);const{data:s}=await I(i==null?void 0:i.id),d=(t=s==null?void 0:s.centerNotificationPersons)==null?void 0:t.map(m=>m.userId);B(S.filter(m=>d==null?void 0:d.includes(m.id))),A(s==null?void 0:s.type),w(s==null?void 0:s.isPublic),E(new Date(s==null?void 0:s.beginningDate)),U(new Date(s==null?void 0:s.endingDate)),C("title",s==null?void 0:s.title),C("text",s==null?void 0:s.text),o(!0)}},xe=()=>{i&&R({content:"آیا از حذف این اطلاعیه مطمئن هستید؟"}).then(async()=>{await y(i.id),c(),j(void 0)}).catch(()=>{})},me=async t=>{const{title:s,text:d}=t,m=N.map(u=>({userId:u.id})),W={title:String(s),text:String(d),type:O,beginningDate:_(q,J),endingDate:_($,Q),isPublic:D,clinicId:n,officeId:f,centerNotificationPersons:N.length?m:void 0};try{K(!0),x?(await P(i==null?void 0:i.id,{id:i==null?void 0:i.id,...W}).then(u=>u.errors.length===0&&ee.success(u.message)),o(!1),c()):(await g(W).then(u=>u.errors.length===0&&ee.success(u.message)),o(!1),c()),K(!1)}catch(u){console.log("have error ",u.response)}},fe=[{item:e.jsx(G,{onClick:de,children:e.jsx(ke,{fontSize:"large",color:"success"})}),expectedRoles:M.AddNotification},{item:e.jsx(G,{onClick:ue,children:e.jsx(Ie,{fontSize:"large",color:i?"primary":"disabled"})}),expectedRoles:M.EditNotification},{item:e.jsx(G,{onClick:xe,children:e.jsx(Pe,{fontSize:"large",color:i?"error":"disabled"})}),expectedRoles:M.DeleteNotification}];return e.jsxs(e.Fragment,{children:[e.jsx(ie,{direction:"row",columnGap:1,children:fe.filter(t=>r(void 0,[t.expectedRoles])===!0).map(t=>t.item)}),z&&e.jsxs(Re,{fullScreen:!0,title:x?"ویرایش اطلاعیه":"افزودن اطلاعیه",maxWidth:"sm",onClose:()=>o(!1),children:[e.jsx(he,{sx:{paddingBottom:0},children:e.jsxs(l,{container:!0,component:"form",paddingY:1,spacing:2,children:[e.jsx(l,{item:!0,xs:12,md:6,children:e.jsx(Te,{items:Fe,onchange:t=>A(Number(t)),value:O,label:"نوع پیام"})}),e.jsx(l,{item:!0,md:6,xs:12,children:e.jsxs(be,{row:!0,"aria-labelledby":"demo-row-radio-buttons-group-label",name:"row-radio-buttons-group",style:{paddingRight:"10px"},value:D,onChange:t=>t.target.value==="true"?w(!0):w(!1),children:[e.jsx(te,{value:!0,control:e.jsx(se,{}),label:"پیام عمومی"}),e.jsx(te,{value:!1,control:e.jsx(se,{}),label:"پیام خصوصی"})]})}),e.jsx(l,{item:!0,md:6,xs:12,children:e.jsx(H,{label:"عنوان",name:"title",register:h,validation:{required:!0},error:!!b.title})}),e.jsx(l,{item:!0,md:6,xs:12,children:e.jsx(je,{multiple:!0,disabled:D,id:"checkboxes-tags-demo",options:S,value:N,onChange:ce,size:"small",disableCloseOnSelect:!0,getOptionLabel:t=>`${t.fullName} `,renderTags:(t,s)=>t.map((d,m)=>e.jsx(ye,{variant:"filled",sx:{fontSize:"0.6rem",margin:0},label:`${d.fullName}`,size:"small",...s({index:m})})),renderOption:(t,s,{selected:d})=>e.jsxs("li",{...t,style:{fontSize:"0.8rem",padding:0,margin:0},children:[e.jsx(Se,{icon:He,checkedIcon:Ve,style:{marginRight:2,padding:"5px"},checked:d}),`${s.fullName}`]}),style:{width:"auto",fontSize:"12px"},renderInput:t=>e.jsx(H,{...t,name:"users",register:h,validation:{required:!(N.length||D)},error:!!b.users,label:"کاربران",placeholder:"نام نام خانوادگی"})})}),e.jsx(l,{item:!0,md:3,xs:12,children:e.jsx(Y,{label:"تاریخ شروع",value:q,disablePast:!1,onChange:t=>E(t)})}),e.jsx(l,{item:!0,md:3,xs:12,children:e.jsx(Z,{label:"ساعت شروع",value:J,onChange:t=>re(t)})}),e.jsx(l,{item:!0,md:3,xs:12,children:e.jsx(Y,{label:"تاریخ پایان",value:$,disablePast:!1,onChange:t=>U(t)})}),e.jsx(l,{item:!0,md:3,xs:12,children:e.jsx(Z,{label:"ساعت پایان",value:Q,onChange:t=>le(t)})}),e.jsx(l,{item:!0,xs:12,children:e.jsx(H,{multiline:!0,rows:4,label:"متن",name:"text",register:h,validation:{required:!0},error:!!b.text})})]})}),e.jsx(Le,{style:{paddingBottom:"15px"},onClose:()=>o(!1),onSubmit:T(me),loading:ne})]})]})},Ke=[{title:"نوع پیام",dataIndex:"type",key:"type",width:60,render:(r,n)=>n.type===0?"اطلاع رسانی":n.type===1?"هشدار":"اخطار"},{title:"عنوان پیام",dataIndex:"title",key:"title",width:100},{title:"متن پیام",dataIndex:"text",key:"text",width:180,render:r=>e.jsx(Ee,{title:r,maxLengthValue:60})},{title:"نوع دسترسی",dataIndex:"isPublic",key:"isPublic",width:70,render:(r,n)=>n.isPublic?"عمومی":"خصوصی"}],qe=()=>{const{NotificationsList:r,loading:n,getData:f,setRowSelected:p}=F();a.useEffect(()=>{f()},[]);const i=c=>{p(c)};return e.jsx(Be,{loading:n,rowKey:"id",columns:Ke||[],data:r||[],onClick:c=>i(c),boxProps:{height:"75vh"}})},$e=()=>{const{getData:r,search:n}=F();return e.jsxs(Me,{className:"!space-y-3 !py-2 !px-4 bg-white",children:[e.jsx(Ce,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"مدیریت اطلاعیه ها"}),e.jsx(Ue,{onRefresh:r,onSearch:n,title:"مدیریت اطلاعیه ها"}),e.jsx(Oe,{}),e.jsx(qe,{})]})},tt=()=>e.jsx(Ge,{children:e.jsx($e,{})});export{tt as default};
