import{j as t,c as A,S as f,W as D,B as I}from"./vendor-mui-CBBEb17G.js";import{B as P}from"./index-DQbmBtLN.js";import{a as d}from"./vendor-react-BBazpZul.js";import{aO as R,v as T,by as B,aP as v,x as N,at as E,aQ as F,aX as O,I as u,z as g,J as j}from"./index-DdWwwZXu.js";import{P as W}from"./index-EPtOEpu_.js";import{S as z}from"./index-CDArk_1r.js";import"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";const K=({onClose:n,onSubmit:p,selectedItem:o,loading:a})=>{const{handleSubmit:x,control:r,formState:{errors:h}}=R({defaultValues:{name:(o==null?void 0:o.name)??""}}),y=s=>{p({name:s.name})};return t.jsxs(T,{title:o?"ویرایش نوع گزارش پاراکلینیک":"افزودن نوع گزارش پاراکلینیک جدید",maxWidth:"xs",onClose:n,children:[t.jsx(A,{className:"m-1 !p-2",children:t.jsx(f,{component:"form",children:t.jsx(B,{name:"name",control:r,defaultValue:"",rules:{required:!0},render:({field:{onChange:s,value:m}})=>t.jsx(v,{label:"عنوان",fullWidth:!0,error:!!h.name,className:"!mt-1",value:m,onChange:s})})})}),t.jsx(N,{onClose:n,onSubmit:x(y),loading:a})]})},M=()=>{const n=new W,p=E(),[o,a]=d.useState(!1),[x,r]=d.useState(!1),[h,y]=d.useState([]),[s,m]=d.useState(null),l=async()=>{try{a(!0),m(null);const{data:e}=await n.getAsync();e&&y(e)}finally{a(!1)}},b=async e=>{try{a(!0);const{data:i}=await n.toggledAsync(e);j.success("تغییر وضعیت با موفقیت انجام شد"),l()}finally{a(!1)}},C=async e=>{try{a(!0);let i=null;if(s){const{message:c}=await n.updateAsync({id:s.id,name:e.name});i=c}else{const{message:c}=await n.addAsync({name:e.name});i=c}i&&j.success(i),r(!1),l()}finally{a(!1)}},S=async()=>{try{if(a(!0),!s)return;p({content:"آیا از حذف این نوع گزارش اطمینان دارید؟"}).then(async()=>{const{message:e}=await n.deleteAsync(s.id);j.success(e),l()}).catch(()=>{})}finally{a(!1)}};d.useEffect(()=>{l()},[]);const k=[{title:"ردیف",key:"num",width:70,render:(e,i,c)=>g(c+1)},{title:"شناسه",key:"id",dataIndex:"id",width:70,render:e=>g(e)},{title:"عنوان",key:"name",dataIndex:"name",width:200},{title:"وضعیت",key:"isDelete",dataIndex:"isDelete",width:70,render:(e,i)=>t.jsx(I,{variant:"contained",size:"small",color:e?"error":"success",onClick:()=>b(i.id),children:e?"غیر فعال":"فعال"})}],w=[{id:1,title:"جدید",icons:t.jsx(u.AddIcon,{color:"success"}),disabled:!1,onClick:()=>r(!0)},{id:2,title:"ویرایش",icons:t.jsx(u.EditIcon,{color:"primary"}),disabled:!s,onClick:()=>r(!0)},{id:3,title:"حذف",icons:t.jsx(u.DeleteIcon,{color:"error"}),disabled:!s,onClick:()=>S()},{id:4,title:"بازیابی",icons:t.jsx(u.RefreshIcon,{color:"info"}),disabled:!1,onClick:()=>l()}];return t.jsxs(f,{spacing:1,p:1,height:"80vh",children:[t.jsx(f,{direction:"row",alignItems:"center",spacing:1,children:w.map(e=>t.jsx(D,{title:e.title,children:t.jsx(F,{onClick:e.onClick,disabled:e.disabled,children:e.icons})},e.id))}),t.jsx(f,{className:"!h-[75dvh]",children:t.jsx(O,{columns:k,data:h,rowKey:"id",loading:o,onClick:e=>m(e)})}),x&&t.jsx(K,{selectedItem:s,onSubmit:C,loading:o,onClose:()=>r(!1)})]})},G=()=>t.jsxs(z,{className:"!px-4 !py-2 !space-y-2",children:[t.jsx(P,{prevRoutes:[{path:"/",title:"داشبورد"},{path:"/",title:"پاراکلینیک"}],currentRoute:"نوع گزارش پاراکلینیک"}),t.jsx(M,{})]});export{G as default};
