import{j as i,S as Q,M as c,a8 as G}from"./vendor-mui-CBBEb17G.js";import{aP as V,cC as X,w as $,aQ as b,I as w,aX as q,a$ as H,z as E,fI as W,fJ as Y}from"./index-IP_FWtso.js";import{a as l}from"./vendor-react-BBazpZul.js";const Z=[{label:"فعال",value:""},{label:"غیر فعال",value:"1"}],le=({doctorId:p,assistantId:z,setSelectedServices:g,currentServiceIds:ee,selectedRow:o})=>{var N,j,k;const{GetCenterServices:O}=W(),{getServiceDetailGroupSelectListAsync:P}=Y(),[T,d]=l.useState(0),[m,h]=l.useState({page:1,size:25}),[t,_]=l.useState(),[te,L]=l.useState(null),[x,S]=l.useState(),[n,u]=l.useState([]),[v,C]=l.useState(""),[D,f]=l.useState(null),y=async()=>{try{d(s=>s+=1);const e={title:v||void 0,PageNumber:m.page,PageSize:m.size,serviceDetailId:o==null?void 0:o.serviceDetailId,ServiceDetailGroupId:x,[p?"SkipDoctorService":"SkipAssistantService"]:o?void 0:p||z,isDelete:D?!!D.value:void 0},{data:a}=await O(e);if(!a)return;_({...a,list:a.list})}finally{d(e=>e-=1)}},A=async()=>{try{d(s=>s+=1);const{data:e}=await P({});if(!e)return;const a=e.map(s=>({label:s.name,value:s.id.toString()}));L(a)}catch(e){console.log("ERROR_IN_GET_SERVICE_GROUP_LIST",e)}finally{d(e=>e-=1)}},M=async()=>{C(""),f(null),S(void 0),h({page:1,size:25})},R=e=>{},U=e=>{if(!t)return;if(!e){const s=t.list.map(I=>I.serviceDetailId),r=n.filter(I=>!s.includes(I));return u(r)}const a=[...n,...t.list.map(s=>s.serviceDetailId)];return u(a)},B=(e,a)=>{if(a){const s=[...n,e];u(s)}else{const s=[...n].filter(r=>r!==e);u(s)}};l.useEffect(()=>{y()},[m]),l.useEffect(()=>{A()},[]),l.useEffect(()=>{g(n)},[n,g]);const K=T>0,F=l.useMemo(()=>(t==null?void 0:t.list.every(e=>n.includes(e.serviceDetailId)))??!1,[t==null?void 0:t.list,n]),J=[{title:i.jsx(G,{className:"!m-0 !p-0 !rounded-sm !bg-white",onChange:(e,a)=>U(a),checked:F}),key:"check",width:60,render:(e,a)=>i.jsx(G,{className:"!m-0 !p-0",onChange:(s,r)=>B(a.serviceDetailId,r),checked:n.some(s=>s===a.serviceDetailId)})},{title:"کد خدمت",dataIndex:"serviceDetailId",key:"serviceDetailId",width:100,render:(e,a)=>E(a.serviceDetailCustomId||e)},{title:"کد ملی ",dataIndex:"serviceDetailNationalCode",key:"serviceDetailNationalCode",width:100,render:e=>e?E(e):"-"},{title:"عنوان",dataIndex:"serviceName",key:"serviceName",width:300},{title:"نام گروه",dataIndex:"serviceDetailGroupName",key:"serviceDetailGroupName",width:150,render:e=>e||"-"}];return i.jsxs(Q,{spacing:2,children:[!o&&i.jsxs(c,{container:!0,xs:12,spacing:1,children:[i.jsx(c,{item:!0,xs:12,sm:2.5,children:i.jsx(V,{label:"عنوان خدمت",placeholder:"ویزیت...",value:v,onChange:e=>C(e)})}),i.jsx(c,{item:!0,xs:12,sm:4,children:i.jsx(X,{value:x,onChange:S})}),i.jsx(c,{item:!0,xs:12,sm:2.5,children:i.jsx($,{label:"وضعیت خدمت",selectOption:Z,value:D,onChange:e=>f(e)})}),i.jsxs(c,{item:!0,xs:1,display:"flex",flexDirection:"row",gap:1,children:[i.jsx(b,{color:"primary",onClick:y,children:i.jsx(w.SearchIcon,{})}),i.jsx(b,{color:"info",onClick:M,children:i.jsx(w.RefreshIcon,{})})]})]}),i.jsx(q,{loading:K,rowKey:"serviceDetailId",columns:J||[],data:H((t==null?void 0:t.list)??[]).groupBy(e=>e.serviceDetailId).map((e,a)=>({serviceDetailId:e[0].serviceDetailId,serviceName:e[0].serviceName,serviceDetailNationalCode:e[0].serviceDetailNationalCode,serviceDetailGroupName:e[0].serviceDetailGroupName})).value()||[],totalCount:((N=t==null?void 0:t.pagination)==null?void 0:N.totalCount)??0,pageNumber:(((j=t==null?void 0:t.pagination)==null?void 0:j.pageNumber)??1)-1,pageSize:((k=t==null?void 0:t.pagination)==null?void 0:k.pageSize)??25,onPaginationLoad:(e,a)=>h({page:e+1,size:a}),onClick:e=>R()})]})};export{le as C};
