import{j as e,p as h,Y as U,Z as j,$ as E,U as x,V as l,a0 as u,a8 as P,S,o as H}from"./vendor-mui-CBBEb17G.js";import{aT as R,dL as A,dM as _,dN as y,dO as B,ao as I,C as $}from"./index-DdWwwZXu.js";import{a as N}from"./vendor-react-BBazpZul.js";const G=({onSelect:f,isSalamatInsurance:g,drugListSearch:c,loading:z,serachQuery:b,onLoad:w,totalCount:d,pageNumber:C,pageSize:v,selectedDrugs:m,showAdd:T=!0})=>{const[s,i]=N.useState(),k=a=>{var t,r;const o={format:a.format,genericCode:a.genericCode,name:`${a.comment}@${p(((t=a.comment)==null?void 0:t.toUpperCase())||"",(r=a.fullName)==null?void 0:r.toUpperCase())}`,nationalNumber:a.irc,wsSrvCode:a.erx,code:g?a.genericCode:a.erx};s!=null&&s.some(n=>n.nationalNumber===o.nationalNumber)?i(s.filter(n=>n.nationalNumber!=o.nationalNumber)):i(n=>[...n??[],o])},p=(a,o)=>{let t="";return o.split("").forEach((r,n)=>{r!=a.charAt(n)&&(t+=r)}),t};return N.useEffect(()=>{m&&i(m)},[m]),e.jsxs(h,{className:"relative h-[calc(100%-100px)] min-h-[300px] mt-2 border rounded-lg overflow-auto",children:[e.jsxs("div",{className:"m-2",children:[e.jsx(R,{color:"success"}),e.jsx("span",{className:"font-bold mr-1",children:"نتیجه جستجو"})]}),e.jsx(U,{className:" absolute top-[40px] bottom-0 left-0 rhigt-0 !mb-[55px] overflow-auto ",children:e.jsxs(j,{stickyHeader:!0,size:"small",children:[e.jsx(E,{sx:{borderRadius:"12px"},children:e.jsxs(x,{children:[e.jsx(l,{width:30,align:"center",className:"!bg-blue-800 !text-white"}),e.jsx(l,{className:"!bg-blue-800 !text-white w-[80px]",children:"نوع دارو"}),e.jsx(l,{className:"!bg-blue-800 !text-white min-w-[80px]",children:"کد ERX"}),e.jsx(l,{className:"!bg-blue-800 !text-white min-w-[90px]",children:"کد ژنریک"}),e.jsx(l,{className:"!bg-blue-800 !text-white",children:"نام دارو"}),e.jsx(l,{className:"!bg-blue-800 !text-white",children:"توضیحات"})]})}),e.jsx(u,{children:c==null?void 0:c.map(a=>{var o,t,r;return e.jsxs(x,{hover:!0,className:"!cursor-pointer",onClick:()=>k(a),sx:{"&:hover":{backgroundColor:"#c1eeff !important"}},children:[e.jsx(l,{className:"!py-0",children:e.jsx(P,{className:"!p-0 !m-0",checked:!!(s!=null&&s.some(n=>n.nationalNumber==a.irc))})}),e.jsx(l,{children:A[a.format]}),e.jsx(l,{children:a.erx}),e.jsx(l,{children:a.genericCode}),e.jsx(l,{children:e.jsx(_,{className:"cursor-pointer noselect",searchWords:[b],autoEscape:!0,textToHighlight:(o=a.comment)!=null&&o.trim().length?a.comment:a.fullName})}),e.jsxs(l,{children:[" ",e.jsx(y,{serachQuery:b,value:p(((t=a.comment)==null?void 0:t.toUpperCase())||"",(r=a.fullName)==null?void 0:r.toUpperCase()),maxLengthValue:45})," "]})]},a.irc)})})]})}),d&&e.jsx(j,{className:"absolute bottom-0 left-0 right-0 z-10 bg-gray-50 w-full",children:e.jsx(u,{children:e.jsx(x,{children:e.jsx(B,{className:"!pr-[35%]",align:"center",totalCount:d,initialPage:C,initialRowsPerPage:v||50,onPageChange:w})})})}),T&&(s==null?void 0:s.length)&&e.jsx(h,{className:"absolute bottom-2 right-4 z-10 bg-gray-50  ",children:e.jsx(I,{className:"!bg-orange-600 animate-[bounce_2s_ease-in-out_infinite] hover:animate-none !pr-[40px] w-[250px]",children:e.jsxs(S,{direction:"row",alignItems:"center",width:"100%",children:[e.jsx(h,{onClick:()=>f(s),children:`افزودن به لیست ( ${s==null?void 0:s.length} مورد)`}),e.jsx(H,{onClick:()=>{i([])},className:"!mr-auto !text-white",children:e.jsx($,{})})]})})})]})};export{G as D};
