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