import{a6 as je,a9 as De,j as e,S as p,ab as ve,W as _,M as V,r as K,aF as ye,o as we}from"./vendor-mui-CBBEb17G.js";import{ex as Ce,al as z,gk as l,at as ke,e as Me,aA as j,J as Te,g6 as Ie,be as A,aQ as q,gr as Ne,gs as Re,aP as Pe,gn as Ve,dD as ze,I as R,gY as Fe,ao as H,gZ as Le,Y as O,aU as Ue,aV as Ye,aX as E,bc as W,a_ as P}from"./index-DdWwwZXu.js";import{a as o}from"./vendor-react-BBazpZul.js";import{g as Q}from"./vendor-utils-BveVE6Uf.js";import{r as X}from"./vendor-charts-tGnAgELZ.js";import{S as _e}from"./singleSmsModal-Dm1TaWGJ.js";import{S as Ae}from"./index-V61oU0GE.js";import"./persian-tools.esm-8oAIvm4W.js";const qe=Ce(t=>({reportSection:{width:"100%",height:"100vh"},sidebar:{borderLeft:"1px solid #ccc",padding:"25px 10px",flexDirection:"column",gap:"8px",overflowY:"scroll"}})),J=z("div")`
  background: #6dc9ff;
  color: #fff;
  padding: 5px 0px;
  text-align: center;
  border-radius: 20px;
  font-size: 0.9rem;
`,D=z(je)`
  .MuiTypography-root {
    font-size: 0.9rem;
  }
  &.MuiFormControlLabel-root {
    min-width: 150px;
    color: rgba(0, 0, 0, 0.5);
    margin: 1px;
  }
`,v=z(De)`
  &.MuiRadio-root {
    padding: 2px 5px;
    color: rgba(0, 0, 0, 0.5);
  }
`,Z=o.createContext(void 0),Ee=({children:t})=>{const[s,a]=o.useState(!1),[c,i]=o.useState(l.Today),[h,g]=o.useState(new Date),[S,x]=o.useState(new Date),[r,u]=o.useState(),[m,y]=o.useState(),[d,b]=o.useState(),[$,ee]=o.useState(""),[te,se]=o.useState([]),[F,ae]=o.useState([]),[T,ne]=o.useState(1),[I,re]=o.useState(25),[oe,le]=o.useState(),[w,ce]=o.useState("sent"),[L,ie]=o.useState(),de=ke(),{clinicId:ue,officeId:xe}=Me(n=>n.doctorData),{getSendSmsAsync:me,getScheduledSmsAsync:he,getReceivedMessagesAsync:pe,deleteScheduledSms:ge}=Ie(),Se=()=>{const n=new Date(new Date().setHours(0)),f=new Date(new Date().setHours(0));switch(c){case l.Today:g(n),x(f);break;case l.LastDay:g(new Date(n.setDate(n.getDate()-1))),x(f);break;case l.lastWeek:g(new Date(n.setDate(n.getDate()-7))),x(f);break;case l.lastMonth:g(new Date(n.setMonth(n.getMonth()-1))),x(f);break;case l.lastYear:g(new Date(n.setFullYear(n.getFullYear()-1))),x(f);break;case l.betweenDate:g(n),x(f);break}},U=async()=>{try{a(!0);const{data:n}=await me({From:j(h),UpTo:j(S),Mobiles:F.map(f=>f.phoneNumber),PageNumber:T,PageSize:I});if(!n)return;u(n)}catch{}finally{a(!1)}},N=async()=>{try{a(!0);const{data:n}=await he({from:j(h),upto:j(S)});if(!n)return;y(n)}finally{a(!1)}},Y=async()=>{try{a(!0);const{data:n}=await pe({From:j(h),UpTo:j(S),ClinicId:ue,OfficeId:xe,PageNumber:T,PageSize:I,Text:L});if(!n)return;b(n)}catch{}finally{a(!1)}},fe=n=>{de({content:"آیا از لغو ارسال این پیام اطمینان دارید؟"}).then(async()=>{try{a(!0);const{message:f}=await ge(n);Te.success(f),N()}finally{a(!1)}}).catch(async()=>{})};o.useEffect(()=>{Se()},[c]),o.useEffect(()=>{w==="sent"&&U(),w==="scheduled"&&N(),w==="received"&&Y()},[I,T,w]);const be={loading:s,getScheduledSms:N,getReceivedMessages:Y,getSendSms:U,dateRadioValue:c,setDateRadioValue:i,fromDateValue:h,setFromDateValue:g,setToDateValue:x,toDateValue:S,setScheduledSms:y,setSentSmsList:u,scheduledSms:m,sentSmsList:r,setLoading:a,phoneNumber:$,setPhoneNumber:ee,setSmsShowList:se,smsShowList:te,mobileList:F,setMobileList:ae,setPageNumber:ne,setPageSize:re,selectedSms:oe,setSelectedSms:le,smsType:w,setSmsType:ce,receivedSms:d,setReceivedSms:b,handleDeleteSchduledSms:fe,text:L,setText:ie};return e.jsx(Z.Provider,{value:be,children:t})},M=()=>o.useContext(Z),Be=()=>{const{dateRadioValue:t,setDateRadioValue:s,fromDateValue:a,setFromDateValue:c,toDateValue:i,setToDateValue:h}=M(),g=x=>{s(x.target.value)},S=x=>{const r=x==="prev"?-1:1,u=new Date(a),m=new Date(i);switch(t){case l.Today:h(new Date(m.setDate(m.getDate()+1*r))),c(new Date(u.setDate(u.getDate()+1*r)));break;case l.LastDay:h(new Date(m.setDate(m.getDate()+1*r))),c(new Date(u.setDate(u.getDate()+1*r)));break;case l.lastWeek:h(new Date(m.setDate(m.getDate()+7*r))),c(new Date(u.setDate(u.getDate()+7*r)));break;case l.lastMonth:h(new Date(m.setMonth(m.getMonth()+1*r))),c(new Date(u.setMonth(u.getMonth()+1*r)));break;case l.lastYear:h(new Date(m.setFullYear(m.getFullYear()+1*r))),c(new Date(u.setFullYear(u.getFullYear()+1*r)));break}};return e.jsxs(p,{gap:1,children:[e.jsx(J,{children:"انتخاب تاریخ"}),e.jsxs(ve,{"aria-labelledby":"demo-controlled-radio-buttons-group",name:"controlled-radio-buttons-group",value:t,onChange:g,style:{display:"flex",flexDirection:"row"},children:[e.jsx(D,{value:l.Today,control:e.jsx(v,{}),label:"امروز"}),e.jsx(D,{value:l.LastDay,control:e.jsx(v,{}),label:"یک روز گذشته"}),e.jsx(D,{value:l.lastWeek,control:e.jsx(v,{}),label:"هفت روز گذشته"}),e.jsx(D,{value:l.lastMonth,control:e.jsx(v,{}),label:"سی روز گذشته"}),e.jsx(D,{value:l.lastYear,control:e.jsx(v,{}),label:"یکسال گذشته"}),e.jsx(D,{value:l.betweenDate,control:e.jsx(v,{}),label:"بین دو تاریخ"})]}),e.jsx(p,{marginTop:1,children:e.jsx(A,{label:"از تاریخ",disablePast:!1,disabled:t!==l.betweenDate,value:a,onChange:x=>c(x)})}),e.jsx(p,{marginTop:.5,children:e.jsx(A,{label:"تا تاریخ",disablePast:!1,disabled:t!==l.betweenDate,value:i,onChange:x=>h(x)})}),e.jsxs(p,{direction:"row",justifyContent:"center",gap:1,paddingX:1,children:[e.jsx(_,{title:" بعد",children:e.jsx(p,{children:e.jsx(q,{onClick:()=>S("next"),disabled:t===l.betweenDate||t===l.Today,children:e.jsx(Ne,{})})})}),e.jsx(_,{title:" قبل",children:e.jsx(p,{children:e.jsx(q,{onClick:()=>S("prev"),disabled:t===l.betweenDate,children:e.jsx(Re,{})})})})]})]})},Ge=()=>{const{setMobileList:t,mobileList:s}=M(),[a,c]=o.useState(!1),[i,h]=o.useState(""),g=r=>{const u=s.filter(m=>m.id!==r);t(u)},S=()=>{if(i.length!==11)return;if(!Fe(i))return c(!0);const u=s.length?s[s.length-1].id:void 0,m=[...s,{id:u??1,phoneNumber:i}];t(m),c(!1),h("")},x=r=>{r.key==="Enter"&&S()};return e.jsxs(p,{gap:2,children:[e.jsx(J,{children:"فیلتر"}),e.jsxs("div",{className:"relative",children:[e.jsx(Pe,{value:i,onKeyDown:x,inputProps:{maxLength:11,className:"!pl-4"},onChange:r=>Ve(r,h),error:a,label:"شماره موبایل"}),e.jsx(ze,{disabled:i.length!==11,color:"success",onClick:S,className:"!absolute !left-0 !top-1/2 !-translate-y-1/2",children:e.jsx(R.AddIcon,{color:i.length===11?"success":"disabled"})})]}),s.map(r=>e.jsxs("div",{className:"relative w-full p-[6px] bg-gray-200 rounded-xl",children:[e.jsx(R.CloseIcon,{color:"error",onClick:()=>g(r.id),className:"!absolute !left-2 !top-1/2 !-translate-y-1/2 !cursor-pointer"}),e.jsx("p",{className:"text-center",children:r.phoneNumber})]}))]})},Ke=()=>{const{smsType:t,getSendSms:s,getScheduledSms:a,getReceivedMessages:c}=M(),i=()=>{if(t==="sent")return s();if(t==="scheduled")return a();if(t==="received")return c()};return e.jsxs(p,{gap:2,children:[e.jsx(Be,{}),t==="sent"&&e.jsx(Ge,{}),e.jsx(H,{onClick:i,children:"جستجو"})]})},He=()=>{const t=qe(),[s,a]=o.useState(!1);return e.jsx(e.Fragment,{children:e.jsx(V,{item:!0,xs:12,md:2.5,className:t.sidebar,children:e.jsxs(p,{spacing:2,children:[e.jsx(Ke,{}),e.jsx(H,{color:"warning",fullWidth:!0,onClick:()=>a(!0),className:"!text-white",children:"شارژ پنل پیامک"}),s&&e.jsx(Le,{onClose:()=>a(!1)})]})})})};var C={},B;function Oe(){if(B)return C;B=1;var t=X();Object.defineProperty(C,"__esModule",{value:!0}),C.default=void 0;var s=t(O()),a=K(),c=(0,s.default)((0,a.jsx)("path",{fillRule:"evenodd",d:"M12 2C6.48 2 2 6.48 2 12c0 1.54.36 2.98.97 4.29L1 23l6.71-1.97c1.31.61 2.75.97 4.29.97 5.52 0 10-4.48 10-10S17.52 2 12 2zm4 11h-3v3h-2v-3H8v-2h3V8h2v3h3v2z"}),"MapsUgc");return C.default=c,C}var We=Oe();const Qe=Q(We);var k={},G;function Xe(){if(G)return k;G=1;var t=X();Object.defineProperty(k,"__esModule",{value:!0}),k.default=void 0;var s=t(O()),a=K(),c=(0,s.default)((0,a.jsx)("path",{d:"M10.27 12h3.46c.93 0 1.63-.83 1.48-1.75l-.3-1.79C14.67 7.04 13.44 6 12 6S9.33 7.04 9.09 8.47l-.3 1.79c-.15.91.55 1.74 1.48 1.74zm-8.61-.89c-.13.26-.18.57-.1.88.16.69.76 1.03 1.53 1h1.95c.83 0 1.51-.58 1.51-1.29 0-.14-.03-.27-.07-.4-.01-.03-.01-.05.01-.08.09-.16.14-.34.14-.53 0-.31-.14-.6-.36-.82-.03-.03-.03-.06-.02-.1.07-.2.07-.43.01-.65-.16-.43-.55-.72-.99-.74-.03 0-.05-.01-.07-.03-.17-.21-.48-.35-.83-.35-.3 0-.57.1-.75.26-.03.03-.06.03-.09.02-.14-.06-.3-.09-.46-.09-.65 0-1.18.49-1.24 1.12 0 .02-.01.04-.03.06-.29.26-.46.65-.41 1.05.03.22.12.43.25.6.03.02.03.06.02.09zm14.58 2.54c-1.17-.52-2.61-.9-4.24-.9-1.63 0-3.07.39-4.24.9C6.68 14.13 6 15.21 6 16.39V18h12v-1.61c0-1.18-.68-2.26-1.76-2.74zm-15.02.93C.48 14.9 0 15.62 0 16.43V18h4.5v-1.61c0-.83.23-1.61.63-2.29-.37-.06-.74-.1-1.13-.1-.99 0-1.93.21-2.78.58zm21.56 0c-.85-.37-1.79-.58-2.78-.58-.39 0-.76.04-1.13.1.4.68.63 1.46.63 2.29V18H24v-1.57c0-.81-.48-1.53-1.22-1.85zM22 11v-.5c0-1.1-.9-2-2-2h-2c-.42 0-.65.48-.39.81l.7.63c-.19.31-.31.67-.31 1.06 0 1.1.9 2 2 2s2-.9 2-2z"}),"Groups2");return k.default=c,k}var Je=Xe();const Ze=Q(Je),$e=()=>{const[t,s]=o.useState({specificSMS:!1,groupSMS:!1,smsQueue:!1});return e.jsxs(e.Fragment,{children:[e.jsx(p,{direction:"row",justifyContent:"space-between",paddingX:"5px",children:e.jsxs(p,{direction:"row",gap:2,marginLeft:3,children:[e.jsxs(p,{justifyContent:"center",alignItems:"center",className:"cursor-pointer",onClick:()=>s(a=>({...a,specificSMS:!0})),children:[e.jsx(Qe,{color:"primary",fontSize:"large"}),e.jsx("span",{className:"text-[0.9rem]",children:"اختصاصی"})]}),e.jsxs(p,{justifyContent:"center",alignItems:"center",className:"cursor-pointer",onClick:()=>s(a=>({...a,groupSMS:!0})),children:[e.jsx(Ze,{color:"primary",fontSize:"large"}),e.jsx("span",{className:"text-[0.9rem]",children:"گروهی"})]})]})}),t.specificSMS&&e.jsx(_e,{onClose:()=>s(a=>({...a,specificSMS:!1}))}),t.groupSMS&&e.jsx(Ae,{onClose:()=>s(a=>({...a,groupSMS:!1}))})]})},et=()=>{const{smsType:t,setSmsType:s}=M(),a=(i,h)=>{s(h)},c=[{id:1,label:"ارسالی",value:"sent"},{id:2,label:"زمان بندی",value:"scheduled"}];return e.jsx(Ue,{value:t,children:e.jsx(Ye,{variant:"scrollable",scrollButtons:"auto",onChange:a,className:"!min-h-[30px] !py-0 !mr-5 !justify-center",children:c.map(i=>e.jsx(ye,{label:i.label,value:i.value,className:"!mx-1 !py-0 !min-h-[30px] !bg-slate-300 !text-slate-500 !text-[0.9rem] !rounded-t-xl !rounded-b-none aria-selected:!bg-blue-700 aria-selected:!text-white"},i.id))})})},tt=[{title:"گیرنده",dataIndex:"receiver",key:"receiver",width:100},{title:"متن پیام",dataIndex:"text",key:"text",width:250,render:t=>e.jsx(W,{title:t,maxLengthValue:40})},{title:"ساعت ارسال",dataIndex:"sendDate",key:"sendDate",width:100,render:t=>P(t,"time")},{title:"تاریخ ارسال",dataIndex:"sendDate",key:"sendDate",width:100,render:t=>new Date(t).toLocaleDateString("fa-IR-u-nu-latn")},{title:"وضعیت",dataIndex:"isSuccess",key:"isSuccess",width:90,render:t=>t?"ارسال شده":"ارسال نشده"}],st=()=>{var u,m,y;const{loading:t,sentSmsList:s,scheduledSms:a,receivedSms:c,setSelectedSms:i,setPageNumber:h,setPageSize:g,smsType:S,handleDeleteSchduledSms:x}=M(),r=[{title:"گیرندگان",dataIndex:"receivers",key:"receivers",width:100,render:d=>d.flatMap(b=>b.mobile).join(",")},{title:"متن پیام",dataIndex:"text",key:"text",width:250,render:d=>e.jsx(W,{title:d,maxLengthValue:40})},{title:"زمانبندی ارسال",dataIndex:"sendDateTime",key:"sendDateTime",width:100,render:d=>d?P(d,"date-time"):"---"},{title:"تاریخ ارسال",dataIndex:"doneDate",key:"doneDate",width:100,render:d=>d?P(d,"date-time"):"---"},{title:"وضعیت",dataIndex:"isSuccessful",key:"isSuccessful",width:90,render:d=>d?e.jsx("span",{className:"text-green-600",children:"ارسال شده"}):e.jsx("span",{className:"text-blue-600",children:"ارسال نشده"})},{title:"لغو ارسال",dataIndex:"id",key:"id",width:50,render:(d,b)=>e.jsx(we,{color:"error",size:"small",disabled:b.isSuccessful,className:"!m-0 !p-0",onClick:()=>x(d),children:e.jsx(R.CloseIcon,{})})}];return e.jsx(e.Fragment,{children:e.jsxs(p,{children:[e.jsx(et,{}),S==="sent"&&e.jsx(E,{rowKey:"id",loading:t,columns:tt||[],data:(s==null?void 0:s.list)||[],onClick:d=>i(d),totalCount:((u=s==null?void 0:s.pagination)==null?void 0:u.totalCount)??0,pageNumber:(((m=s==null?void 0:s.pagination)==null?void 0:m.pageNumber)??1)-1,pageSize:((y=s==null?void 0:s.pagination)==null?void 0:y.pageSize)??25,onPaginationLoad:(d,b)=>{h(d+1),g(b)},boxProps:{sx:{height:"75vh"}}}),S==="scheduled"&&e.jsx(E,{rowKey:"id",loading:t,columns:r||[],data:a||[],onClick:d=>i(d),boxProps:{sx:{height:"75vh"}}})]})})},at=()=>e.jsx(V,{item:!0,xs:12,md:9.5,paddingY:3,paddingX:1,children:e.jsxs(p,{gap:2,children:[e.jsx($e,{}),e.jsx(st,{})]})}),nt=()=>e.jsxs(V,{container:!0,component:"section",className:"h-full",children:[e.jsx(He,{}),e.jsx(at,{})]}),mt=()=>e.jsx(Ee,{children:e.jsx(nt,{})});export{mt as default};
