import{j as t,c as y,S,W as R}from"./vendor-mui-CBBEb17G.js";import{B as _}from"./index-BkhbTDKf.js";import{a as l}from"./vendor-react-BBazpZul.js";import{L as f}from"./index-BJjF639N.js";import{v as h,aP as j,x as C,J as g,at as I,dD as w,I as x,aX as E}from"./index-IP_FWtso.js";import{S as P}from"./index-DFcW8zf-.js";import"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";const N=l.createContext(null),T=({children:a})=>{const{getAsync:s}=new f,[o,c]=l.useState(!1),[r,n]=l.useState(1),[i,d]=l.useState(50),[u,e]=l.useState(null),[b,m]=l.useState(null),A={states:{loading:o,laboratoryLabelsData:u,selectedLaboratoryLabel:b,pageNumber:r,pageSize:i},actions:{setPageNumber:n,setPageSize:d,setSelectedLaboratoryLabel:m},handlers:{getLaboratoryLabels:async()=>{try{c(!0);const{data:L}=await s({PageNumber:r,PageSize:i});if(!L)return;e(L)}catch(L){console.log("ERROR_IN_GETTING_LABORATORY_LABELS",L)}finally{c(!1)}}}};return t.jsx(N.Provider,{value:A,children:a})},p=()=>l.useContext(N),z=({onClose:a})=>{const{addAsync:s}=new f,{handlers:{getLaboratoryLabels:o}}=p(),[c,r]=l.useState(""),[n,i]=l.useState(!1),d=()=>{r(""),a()},u=async()=>{try{if(!c)return g.warn("عنوان الزامیست");i(!0);const{message:e}=await s({title:c});g.success(e),o(),d()}catch(e){console.log("ERROR_IN_ADDING_LABROTARY_NORM_LABEL",e)}finally{i(!1)}};return t.jsx(h,{title:"افزودن برچسب",onClose:d,maxWidth:"xs",children:t.jsxs(y,{className:"!py-4",children:[t.jsx(j,{label:"عنوان",onChange:e=>r(e)}),t.jsx(C,{loading:n,onClose:d,onSubmit:u})]})})},B=({onClose:a})=>{const{updateAsync:s}=new f,{states:{selectedLaboratoryLabel:o},actions:{setSelectedLaboratoryLabel:c},handlers:{getLaboratoryLabels:r}}=p(),[n,i]=l.useState(""),[d,u]=l.useState(!1),e=()=>{i(""),c(null),a()},b=async()=>{try{if(!o)return;if(!n)return g.warn("عنوان الزامیست");u(!0);const{message:m}=await s({id:o.id,title:n});g.success(m),r(),e()}catch(m){console.log("ERROR_IN_UPDATING_LABROTARY_NORM_LABEL",m)}finally{u(!1)}};return t.jsx(h,{title:"افزودن برچسب",onClose:e,maxWidth:"xs",children:t.jsxs(y,{className:"!py-4",children:[t.jsx(j,{label:"عنوان",defaultValue:o==null?void 0:o.title,onChange:m=>i(m)}),t.jsx(C,{loading:d,onClose:e,onSubmit:b})]})})},O=()=>{const{states:{selectedLaboratoryLabel:a},actions:{setSelectedLaboratoryLabel:s},handlers:{getLaboratoryLabels:o}}=p(),{deleteAsync:c}=new f,[r,n]=l.useState({add:!1,edit:!1}),i=I(),d=()=>{a&&i({content:"آیا از حذف این آیتم مطمئنید؟"}).then(async()=>{const{message:e}=await c(a.id);g.success(e),o(),s(null)})},u=[{title:"افزودن",icon:t.jsx(x.AddIcon,{fontSize:"large",color:"success"}),onClick:()=>n(e=>({...e,add:!0})),disabled:!1},{title:"ویرایش",icon:t.jsx(x.EditIcon,{fontSize:"large",color:a?"primary":"disabled"}),onClick:()=>n(e=>({...e,edit:!0})),disabled:!a},{title:"حذف",icon:t.jsx(x.DeleteIcon,{fontSize:"large",color:a?"error":"disabled"}),onClick:d,disabled:!a},{title:"بازنشانی",icon:t.jsx(x.RefreshIcon,{fontSize:"large",color:"primary"}),onClick:o,disabled:!1}];return t.jsxs(S,{direction:"row",justifyContent:"start",alignItems:"center",spacing:1,children:[u.map(e=>t.jsx(w,{disabled:e.disabled,onClick:e.onClick,children:t.jsx(R,{placement:"top",title:t.jsx("h1",{className:"text-sm",children:e.title}),children:e.icon})})),r.add&&t.jsx(z,{onClose:()=>n(e=>({...e,add:!1}))}),r.edit&&a&&t.jsx(B,{onClose:()=>n(e=>({...e,edit:!1}))})]})},k=()=>{const{states:{loading:a,laboratoryLabelsData:s,pageNumber:o,pageSize:c},actions:{setPageNumber:r,setPageSize:n,setSelectedLaboratoryLabel:i},handlers:{getLaboratoryLabels:d}}=p();l.useEffect(()=>{d()},[o,c]);const u=[{title:"نام",key:"title",dataIndex:"title"}];return t.jsx(S,{className:"!h-[75dvh]",children:t.jsx(E,{rowKey:"id",loading:a,columns:u,data:(s==null?void 0:s.list)||[],totalCount:s==null?void 0:s.pagination.totalCount,pageNumber:((s==null?void 0:s.pagination.pageNumber)||1)-1,pageSize:(s==null?void 0:s.pagination.pageSize)||50,onPaginationLoad:(e,b)=>{r(e+1),n(b)},onClick:e=>i(e)})})},J=()=>t.jsxs(P,{className:"!space-y-3 !px-4 !py-2 bg-white",children:[t.jsx(_,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"مقادیر نرمال آزمایش"}),t.jsxs(T,{children:[t.jsx(O,{}),t.jsx(k,{})]})]});export{J as default};
