import{j as e,S as i,W as H}from"./vendor-mui-CBBEb17G.js";import{u as M,q as O,a as s}from"./vendor-react-BBazpZul.js";import{at as T,R as c,dD as U,ao as g,aX as K,I as d,ga as W,J as q}from"./index-DdWwwZXu.js";import{S as J}from"./index-B3nmkrP9.js";import{A as L}from"./addGroup-CGPvefRt.js";import{S as P}from"./index-CDArk_1r.js";import{B as Q}from"./index-DQbmBtLN.js";import"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";const se=()=>{const{getGeneralHealthInfoGroupAsync:S,deleteGeneralHealthInfoGroupAsync:y}=W(),j=T(),u=M(),{category:m,parent:C}=O(),[f,b]=(C??"-").split("-"),[p,k]=m.split("-"),[w,r]=s.useState(!1),[G,N]=s.useState([]),[D,h]=s.useState([]),[n,x]=s.useState(null),[v,l]=s.useState(!1),o=async()=>{var t;try{r(!0);const{data:a}=await S({categoryId:+p});if(!a)return;const I=((t=a.find(z=>z.id===+f))==null?void 0:t.children)??[];N(I),h(I),x(null)}finally{r(!1)}},A=t=>{h(G.filter(a=>a.name.includes(t)))},B=()=>{try{if(!n)return;j({content:"آیا از حذف این دسته بندی اطمینان دارید؟"}).then(async()=>{const{message:t}=await y(n.id);q.success(t),o()}).catch(()=>{})}finally{r(!1)}},E=()=>{l(!1),o()};s.useEffect(()=>{o()},[]);const R=[{title:"عنوان",key:"name",dataIndex:"name",width:300},{title:"گزینه ها",key:"id",dataIndex:"id",width:50,render:(t,a)=>e.jsx(g,{variant:"contained",color:"warning",size:"small",fullWidth:!0,onClick:()=>u(`${t}-${a.name}/attribute`),children:"نمایش گزینه ها"})}],$=[{id:1,title:"جدید",icone:e.jsx(d.AddIcon,{color:"success",fontSize:"large"}),disabled:!1,onClick:()=>l(!0)},{id:2,title:"ویرایش",icone:e.jsx(d.EditIcon,{color:"primary",fontSize:"large"}),disabled:!n,onClick:()=>l(!0)},{id:3,title:"حذف",icone:e.jsx(d.DeleteIcon,{color:"error",fontSize:"large"}),disabled:!n,onClick:()=>B()}];return e.jsxs(P,{children:[e.jsx("div",{className:"",children:e.jsx(Q,{prevRoutes:[{path:"/",title:"اطلاعات پایه"},{path:`/${c.basicInformation.generalInfo}`,title:"فرم ساز"},{path:`/${c.basicInformation.generalInfo}`,title:k},{path:`/${c.basicInformation.generalInfo}/${m}`,title:b}],currentRoute:"زیرگروه ها"})}),e.jsxs(i,{spacing:1,p:1,children:[e.jsx(i,{width:{xs:"100%",md:"80%",lg:"50%"},children:e.jsx(J,{onRefresh:o,onSearch:A,width:"100%"})}),e.jsxs(i,{direction:"row",spacing:1,alignItems:"cener",children:[$.map(t=>e.jsx(U,{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(g,{size:"small",className:"!mr-auto",onClick:()=>u(-1),children:"بازگشت"})]}),e.jsx(i,{className:"h-[calc(100vh-200px)]",children:e.jsx(K,{columns:R,data:D,rowKey:"id",loading:w,onClick:t=>x(t)})}),v&&e.jsx(L,{onClose:E,selectedItem:n,categoryId:+p,parentId:+f})]})]})};export{se as default};
