import{j as e,c as B,S as d,M as b,W as H}from"./vendor-mui-CBBEb17G.js";import{B as v}from"./index-BkhbTDKf.js";import{aO as z,g7 as k,j1 as K,v as L,by as C,aP as A,r as w,x as U,J as I,at as $,ao as M,I as x,dD as q,aX as F,cA as P,R as N}from"./index-IP_FWtso.js";import{a as r,u as V}from"./vendor-react-BBazpZul.js";import{T as Y}from"./index-Dz6vPtCj.js";import"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";const _=({onClose:i,service:u,selectedItem:s})=>{const{control:f,handleSubmit:p,formState:{errors:l}}=z({defaultValues:{name:(s==null?void 0:s.name)??"",type:(s==null?void 0:s.type)??1,displayMode:(s==null?void 0:s.displayMode)??k.list}}),[j,c]=r.useState(!1),[y,o]=r.useState([]),g=Object.values(k).filter(a=>typeof a=="number").map(a=>({value:a.toString(),label:K[a]})),S=async()=>{try{c(!0);const{data:a}=await u.getGeneralHealthInfoCategoryTypesAsync();a&&o(a.map(n=>({label:n.title,value:n.id})))}finally{c(!1)}},m=async a=>{try{if(c(!0),s){const{message:h}=await u.updateGeneralHealthInfoCategoryAsync({id:s.id,name:a.name,type:a.type,displayMode:a.displayMode});I.success(h),i();return}const{message:n}=await u.addGeneralHealthInfoCategoryAsync({name:a.name,type:a.type,displayMode:a.displayMode});I.success(n),i()}finally{c(!1)}};return r.useEffect(()=>{S()},[]),e.jsxs(L,{onClose:i,title:s?"ویرایش دسته بندی شرح حال":"دسته بندی شرح حال جدید",maxWidth:"xs",children:[e.jsx(B,{className:"m-1 !p-2",children:e.jsxs(d,{component:"form",spacing:2,children:[e.jsx(C,{name:"name",control:f,rules:{required:!0},render:({field:{onChange:a,value:n}})=>e.jsx(A,{value:n,onChange:a,error:!!l.name,label:"عنوان"})}),e.jsx(C,{name:"type",control:f,rules:{required:!0},render:({field:{onChange:a,value:n}})=>e.jsx(w,{items:y,label:"نوع",fullWidth:!0,error:!!l.type,value:n,onchange:a})}),e.jsx(C,{name:"displayMode",control:f,rules:{required:!0},render:({field:{onChange:a,value:n}})=>e.jsx(w,{items:g,label:"نحوه نمایش",fullWidth:!0,error:!!l.displayMode,value:n,onchange:a})})]})}),e.jsx(U,{onClose:i,onSubmit:p(m),loading:j})]})},J=()=>{const i=new P,u=$(),s=V(),[f,p]=r.useState(!1),[l,j]=r.useState([]),[c,y]=r.useState([]),[o,g]=r.useState(null),[S,m]=r.useState(!1),[a,n]=r.useState(""),h=async()=>{try{p(!0);const{data:t}=await i.getGeneralHealthInfoCategoryAsync();t&&j(t),t&&y(t),g(null)}finally{p(!1)}},D=()=>{y(l.filter(t=>t.name.includes(a)||t.typeName.includes(a)))},G=()=>{try{if(!o)return;u({content:"آیا از حذف این دسته بندی اطمینان دارید؟"}).then(async()=>{const{message:t}=await i.deleteGeneralHealthInfoCategoryAsync(o.id);I.success(t),h()}).catch(()=>{})}finally{p(!1)}},T=()=>{m(!1),h()},E=()=>{n(""),y(l)};r.useEffect(()=>{h()},[]);const R=[{title:"عنوان",key:"name",dataIndex:"name",width:200},{title:"نوع",key:"typeName",dataIndex:"typeName",width:100},{title:"نحوه نمایش",key:"displayModeName",dataIndex:"displayModeName",width:100},{title:"گروه",key:"id",dataIndex:"id",width:50,render:(t,W)=>e.jsx(M,{variant:"outlined",color:"primary",size:"small",fullWidth:!0,onClick:()=>s(`${N.basicInformation.generalInfo}/${t}-${W.name}`),children:"نمایش گروه ها"})}],O=[{id:1,title:"جدید",icone:e.jsx(x.AddIcon,{color:"success",fontSize:"large"}),disabled:!1,onClick:()=>m(!0)},{id:2,title:"ویرایش",icone:e.jsx(x.EditIcon,{color:"primary",fontSize:"large"}),disabled:!o,onClick:()=>m(!0)},{id:3,title:"حذف",icone:e.jsx(x.DeleteIcon,{color:"error",fontSize:"large"}),disabled:!o,onClick:()=>G()}];return e.jsxs(b,{container:!0,xs:12,spacing:1,className:"!h-full",children:[e.jsx(b,{item:!0,xs:12,sm:2,children:e.jsxs(d,{className:"h-full overflow-y-auto p-2 pb-10 border-l",spacing:1,children:[e.jsx(Y,{children:"نام"}),e.jsx(A,{label:"عنوان ...",value:a,onChange:n}),e.jsxs(d,{component:"form",direction:"row",justifyContent:"center",gap:1,children:[e.jsx(M,{fullWidth:!0,startIcon:e.jsx(x.SearchIcon,{}),onClick:D,children:"جستجو"}),e.jsx(M,{fullWidth:!0,startIcon:e.jsx(x.RefreshIcon,{}),onClick:E,children:"بازنشانی"})]})]})}),e.jsxs(b,{item:!0,xs:12,sm:10,spacing:1,children:[e.jsx(d,{direction:"row",paddingY:1,spacing:1,children:O.map(t=>e.jsx(q,{disabled:t.disabled,onClick:t.onClick,children:e.jsx(H,{title:e.jsx("h1",{className:"text-sm",children:t.title}),children:t.icone})},t.id))}),e.jsx(d,{className:"h-[calc(100vh-200px)]",children:e.jsx(F,{columns:R,data:c,rowKey:"id",loading:f,onClick:t=>g(t)})}),S&&e.jsx(_,{onClose:T,selectedItem:o,service:i})]})]})},ne=()=>e.jsxs(d,{className:"h-full !px-4 !py-2",children:[e.jsx(v,{prevRoutes:[{path:"/",title:"اطلاعات پایه"},{path:`/${N.basicInformation.generalInfo}`,title:"فرم ساز"}],currentRoute:"دسته بندی"}),e.jsx(J,{})]});export{ne as default};
