import{j as i,a8 as I,c as B,M as n,S as F}from"./vendor-mui-CBBEb17G.js";import{a as r}from"./vendor-react-BBazpZul.js";import{z as f,bc as T,aY as d,v as W,c5 as q,cC as O,aQ as S,I as C,aX as Q,x as U,a$ as X}from"./index-DdWwwZXu.js";import{C as Y}from"./index-DkWwWx7a.js";const Z=({preSelectedItemIds:j,centerTariffId:x,onSubmit:y,onClose:u})=>{const[k,p]=r.useState(!1),[a,v]=r.useState(null),[l,h]=r.useState([]),[g,w]=r.useState(),[D,P]=r.useState(""),[c,K]=r.useState({page:1,size:25}),{getCenterTariffServicesAsync:N}=Y(),b=()=>{if(!a)return!1;const e=l.map(t=>t.serviceDetailId);return a.list.filter(t=>t.price>0).every(t=>e.includes(t.serviceDetailId))??!1},m=async e=>{try{if(!x)return;p(!0);const{data:t}=await N({CenterTriffId:x,PageNumber:c.page,PageSize:c.size,ServiceTitle:e,ServiceDetailGroupId:g});if(!t)return;const s=t.list.filter(V=>j.includes(V.serviceDetailId)),o=[...l,...s];h(X(o).uniqBy("serviceDetailId").value()),v(t)}finally{p(!1)}},z=()=>{if(!a)return;const e=a.list.filter(t=>t.price>0);return h(t=>[...t,...e])},G=(e,t)=>{if(t){const s=[...l,e];h(s)}else{const s=l.filter(o=>o.id!==e.id);h(s)}},A=()=>{u()},L=()=>{y(l),u()},M=()=>{m(D)},E=()=>{m()};r.useEffect(()=>{c.page&&c.size&&m()},[c.page,c.size]);const R=[{title:i.jsx(I,{className:"!m-0 !p-0 !rounded-sm !bg-white",onChange:()=>z(),checked:b()}),key:"check",width:60,render:(e,t)=>i.jsx(I,{disabled:t.price===0,className:"!m-0 !p-0",onChange:(s,o)=>G(t,o),checked:l.some(s=>s.id===t.id)})},{title:"کد خدمت",key:"serviceDetailId",dataIndex:"serviceDetailId",width:100,render:(e,t)=>f(t.serviceDetailCustomId||e)},{title:"کد ملی ",key:"nationalCode",dataIndex:"nationalCode",width:120,render:e=>e?f(e):"---"},{title:"نام خدمت",key:"serviceName",dataIndex:"serviceName",width:200,render:(e,t)=>i.jsx(T,{title:t.serviceDetailCustomName||e||"---",maxLengthValue:40})},{title:"نام گروه",key:"serviceGroupName",dataIndex:"serviceGroupName",render:e=>e??"---",width:100},{title:"مبلغ",key:"price",dataIndex:"price",render:e=>d(e),width:100},{title:"مبلغ K حرفه‌ای",key:"professionalKPrice",dataIndex:"professionalKPrice",render:e=>d(e),width:120},{title:"مبلغ K فنی",key:"technicalKPrice",dataIndex:"technicalKPrice",render:e=>d(e),width:100},{title:"مبلغ K بیهوشی",key:"anesthesiologistKPrice",dataIndex:"anesthesiologistKPrice",render:e=>d(e),width:120},{title:"مبلغ K دندان پزشکی",key:"dentalKPrice",dataIndex:"dentalKPrice",render:e=>d(e),width:120}];return i.jsx(W,{title:"انتخاب خدمت از تعرفه",onClose:u,maxWidth:"lg",children:i.jsx(B,{className:"!py-4 !min-h-[380px]",children:i.jsxs(n,{container:!0,xs:12,spacing:1,children:[i.jsxs(n,{container:!0,item:!0,xs:12,spacing:1,children:[i.jsx(n,{item:!0,xs:4,children:i.jsx(q,{fullWidth:!0,label:"جستجو براساس کد/ نام خدمت",onChange:P})}),i.jsx(n,{item:!0,xs:3,children:i.jsx(O,{value:g,onChange:e=>w(e)})}),i.jsx(n,{item:!0,xs:1,children:i.jsxs(F,{direction:"row",alignItems:"center",gap:1,children:[i.jsx(S,{color:"primary",onClick:()=>M(),children:i.jsx(C.SearchIcon,{})}),i.jsx(S,{color:"info",onClick:()=>E(),children:i.jsx(C.RefreshIcon,{})})]})})]}),i.jsx(n,{item:!0,xs:12,className:"min-h-[400px]",children:i.jsx(Q,{rowKey:"serviceDetailId",columns:R,data:(a==null?void 0:a.list)||[],loading:k,totalCount:(a==null?void 0:a.pagination.totalCount)||0,pageNumber:((a==null?void 0:a.pagination.pageNumber)??1)-1,pageSize:(a==null?void 0:a.pagination.pageSize)||25,onPaginationLoad:(e,t)=>{K({page:e+1,size:t})}})}),i.jsx(n,{item:!0,xs:12,children:i.jsx(U,{onClose:A,onSubmit:L})})]})})})};export{Z as S};
