import{j as t,a8 as W,c as J,S as P,aq as te,o as I}from"./vendor-mui-CBBEb17G.js";import{gt as O,e as ae,gu as se,bc as Q,v as U,aP as _,aX as X,x as ie,a$ as ne,fI as oe,J as y,at as ce,c5 as le,bt as re,et as de,bx as ue,aS as me}from"./index-IP_FWtso.js";import{a as n}from"./vendor-react-BBazpZul.js";import"./vendor-utils-BveVE6Uf.js";const fe=({onClose:S,isEdit:f,onCompleted:C,selectedGroup:c})=>{var E,T,q,K,F;const{GetCenterServices:D}=oe(),{addReportServiceGroupAsync:x,updateReportServiceGroupAsync:b}=O(),{clinicId:p,officeId:w}=ae(e=>e.doctorData),[v,h]=n.useState(!1),[u,r]=n.useState(""),[o,k]=n.useState(),[a,N]=n.useState(),[l,m]=n.useState([]),[s,g]=n.useState(""),[R,L]=n.useState({page:1,size:10}),V=e=>{e&&y.success(e),C(),S()},$=()=>u.length?l.length?!0:(y.info("حداقل یک خدمت را انتخاب نمایید"),!1):(y.info("لطفا عنوان را وارد نمایید"),!1),H=async()=>{try{if(h(!0),!$())return;if(f&&c){const{message:e}=await b({id:c==null?void 0:c.id,title:u,services:l.map(i=>({serviceDetailId:i}))});V(e)}else{const{message:e}=await x({title:u,services:l.map(i=>({serviceDetailId:i}))});V(e)}}finally{h(!1)}},A=async(e,i,d)=>{try{h(!0);let j={PageNumber:i??R.page,PageSize:d??R.size};e&&(j={title:e,PageNumber:i??1,PageSize:d??10},L({page:1,size:10}));const{data:z}=await D(j);if(!z)return;const M={...z,list:ne(z.list).uniqBy(ee=>ee.serviceDetailId).value()};k(M),N(M)}finally{h(!1)}},Y=(e,i)=>{m(i?d=>[...d,e]:d=>d.filter(j=>j!==e))},Z=()=>{l.length?m([]):m((o==null?void 0:o.list.map(e=>e.serviceDetailId))??[])},B=se(s,700);n.useMemo(()=>{A(B)},[B]),n.useEffect(()=>{A()},[]),n.useEffect(()=>{!c||!f||(r(c==null?void 0:c.title),m(c.services.map(e=>e.serviceDetailId)))},[c,f]);const G=[{title:t.jsx(W,{className:"!m-0 !p-0 !text-white",checked:l.length===((E=o==null?void 0:o.list)==null?void 0:E.length),indeterminate:!!l.length&&l.length!==(((T=o==null?void 0:o.list)==null?void 0:T.length)??0),onChange:Z}),key:"serviceDetailId",dataIndex:"serviceDetailId",width:20,render:e=>t.jsx(W,{className:"!m-0 !p-0",checked:l.some(i=>i===e),onChange:(i,d)=>Y(e,d)})},{title:"نام خدمت",key:"serviceName",dataIndex:"serviceName",width:120,render:(e,i)=>t.jsx(Q,{title:i.serviceDetailCustomName||e||"",maxLengthValue:45})}];return t.jsxs(U,{onClose:S,title:f?"ویرایش گروه":"افزودن گروه",maxWidth:"sm",children:[t.jsx(J,{className:"m-1 !p-2",children:t.jsxs(P,{spacing:1,children:[t.jsx(_,{label:"عنوان",value:u,onChange:e=>r(e),fullWidth:!0,required:!0}),t.jsx(te,{orientation:"horizontal",className:"w-full",children:"انتخاب خدمات"}),t.jsx(_,{label:"جستجوی نام خدمت",value:s,onChange:e=>g(e)}),t.jsx(X,{columns:G,data:(a==null?void 0:a.list)||[],rowKey:"id",loading:v,totalCount:((q=a==null?void 0:a.pagination)==null?void 0:q.totalCount)??0,pageNumber:(((K=a==null?void 0:a.pagination)==null?void 0:K.pageNumber)??1)-1,pageSize:((F=a==null?void 0:a.pagination)==null?void 0:F.pageSize)??10,onPaginationLoad:(e,i)=>{A(s||void 0,e+1,i),L({page:e+1,size:i})}})]})}),t.jsx(ie,{onClose:S,onSubmit:H,loading:v})]})},pe=({onClose:S})=>{const{getReportServiceGroupAsync:f,deleteReportServiceGroupAsync:C}=O(),c=ce(),[D,x]=n.useState(!1),[b,p]=n.useState(!1),[w,v]=n.useState([]),[h,u]=n.useState([]),[r,o]=n.useState(),k=()=>{try{if(p(!0),!r)return;c({content:"آیا از حذف این گروه اطمینان دارید؟"}).then(async()=>{const{message:s}=await C(r.id);y.success(s),a()}).catch(()=>{})}finally{p(!1)}},a=async()=>{try{p(!0);const{data:s}=await f({});if(!s)return;v(s),u(s),o(void 0)}finally{p(!1)}},N=s=>{w.length&&u(w.filter(g=>g.title.includes(s)))},l=()=>{x(!1),o(void 0)};n.useEffect(()=>{a()},[]);const m=[{title:"عنوان گروه",key:"title",dataIndex:"title",width:150},{title:"خدمات",key:"services",dataIndex:"services",width:200,render:s=>t.jsx(Q,{title:s.map(g=>g.serviceDetailCustomName||g.serviceDetailName).join(",")||"",maxLengthValue:45})}];return t.jsxs(U,{onClose:S,title:"گروه خدمات پذیرش",children:[t.jsxs(J,{className:"m-1 !p-2",children:[t.jsxs(P,{direction:"row",alignItems:"center",spacing:2,mb:1,children:[t.jsx(le,{onChange:N}),t.jsxs(P,{direction:"row",alignItems:"center",spacing:1,children:[t.jsx(I,{onClick:()=>{o(void 0),x(!0)},color:"success",children:t.jsx(re,{fontSize:"small"})}),t.jsx(I,{onClick:()=>x(!0),color:"primary",disabled:!r,children:t.jsx(de,{fontSize:"small"})}),t.jsx(I,{onClick:k,color:"error",disabled:!r,children:t.jsx(ue,{fontSize:"small"})}),t.jsx(I,{onClick:a,color:"info",children:t.jsx(me,{fontSize:"small"})})]})]}),t.jsx(X,{columns:m,data:h,rowKey:"id",loading:b,onClick:s=>o(s)})]}),D&&t.jsx(fe,{isEdit:!!r,onClose:l,onCompleted:a,selectedGroup:r})]})};export{pe as R};
