import{j as e,S as l,c as V,o as z,Q as W,ar as J,R as g}from"./vendor-mui-CBBEb17G.js";import{B as Q}from"./index-BkhbTDKf.js";import{at as X,c5 as Y,ao as Z,c4 as q,dP as _,bg as $,bh as ee,aZ as te,v as se,aP as ae,bE as ne,x as oe,bi as re,a as le,fJ as ie}from"./index-IP_FWtso.js";import{a as o}from"./vendor-react-BBazpZul.js";import{S as ce}from"./index-D7-0uPSw.js";import"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";const de=()=>{const{addServiceDetailGroupAsync:A,deleteServiceDetailGroupAsync:E,getServiceDetailGroupSelectListAsync:M,updateServiceDetailGroupAsync:P}=ie(),G=X(),[j,i]=o.useState(null),[N,c]=o.useState(!1),[S,y]=o.useState(!1),[d,p]=o.useState(""),[h,x]=o.useState(0),[T,u]=o.useState(!1),[a,f]=o.useState(null),[C,R]=o.useState([]),[b,I]=o.useState([]),B=!!j,m=async()=>{try{u(!0);const{data:t}=await M({});t&&R(t),t&&I(t)}finally{u(!1)}},v=(t,r)=>{const s=[];for(let n of r)if(n.name.includes(t)&&s.push(n),n.child){const k=v(t,n.child);k&&s.concat(k)}return s},F=t=>{if(!C.length)return;const r=[];for(let s of C)if(s.name.includes(t)&&r.push(s),s.child){const n=v(t,s.child);n&&r.concat(n)}I(r)},O=(t,r)=>{t.stopPropagation(),i(t.currentTarget),f(r)},H=t=>{t&&t.stopPropagation(),i(null),f(null)},K=t=>{try{u(!0),t.stopPropagation(),a&&G({content:"آیا از حذف این گروه اطمینان دارید؟"}).then(async()=>{await E(a.id),m(),i(null)}).finally(()=>{i(null)})}finally{u(!1)}},w=()=>{y(!1),p(""),x(1),c(!0)},L=()=>{a&&(y(!0),c(!0),p(a.name),x(a.order))},D=(t,r)=>t.map(s=>e.jsx(re,{classes:{selected:"!text-sky-700 !bg-white",content:"!rounded-2xl hover:!bg-sky-100 hover:!text-black !duration-300",focused:"!text-2xl"},className:"rounded-xl ",nodeId:s.id+"",label:e.jsxs(l,{direction:"row",alignItems:"center",gap:.5,py:.6,children:[e.jsx("span",{children:s.name}),e.jsx(z,{"aria-label":"more",id:"long-button","aria-haspopup":"true",classes:{root:"!p-0"},onClick:n=>O(n,{id:s.id,name:s.name,parentId:r,order:s.order}),children:e.jsx(le,{})}),e.jsxs(W,{id:"basic-menu",anchorEl:j,open:B,onClose:H,TransitionComponent:J,classes:{paper:"!shadow-sm !px-4 !py-0 ",list:"!flex !flex-col gap-2 !text-sm"},className:"!shadow-sm relative",anchorOrigin:{vertical:"top",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"right"},children:[e.jsx(g,{onClick:n=>[n.stopPropagation(),w()],children:"افزودن زیرگروه"}),e.jsx(g,{onClick:n=>[n.stopPropagation(),L()],children:"ویرایش"}),e.jsx(g,{onClick:K,children:"حذف"})]})]}),children:s.child&&D(s.child,s.id)},s.id+""));o.useEffect(()=>{m()},[]);const U=async()=>{try{S?await P({id:a==null?void 0:a.id,name:d,order:h,parentId:a==null?void 0:a.parentId}):await A({name:d,order:h,parentId:a?a.id:void 0})}finally{c(!1),m(),i(null)}};return e.jsxs(e.Fragment,{children:[e.jsxs(l,{className:"h-[80vh] overflow-auto p-4 px-16 m-4 border rounded-md",spacing:1,children:[e.jsxs(l,{direction:"row",alignItems:"center",spacing:2,children:[e.jsx(Y,{onChange:F,fullWidth:!0}),e.jsx(Z,{onClick:()=>[f(null),w()],color:"success",startIcon:e.jsx(q,{}),children:"گروه جدید"})]}),e.jsxs(l,{children:[T&&e.jsx(_,{}),b&&e.jsx($,{defaultCollapseIcon:e.jsx(te,{}),defaultExpandIcon:e.jsx(ee,{}),children:D(b)})]}),e.jsx(l,{className:"xp-16"})]}),N&&e.jsx(se,{onClose:()=>c(!1),title:S?"ویرایش گروه":"افزودن گروه",maxWidth:"xs",children:e.jsxs(V,{children:[e.jsxs(l,{paddingY:2,paddingX:1,className:"!space-y-3",children:[e.jsx(ae,{label:"نام گروه",value:d,onChange:p}),e.jsx(ne,{label:"اولویت",type:"number",value:h,onChange:x})]}),e.jsx(oe,{onClose:()=>c(!1),onSubmit:U,disabled:!d})]})})]})},je=()=>e.jsxs(ce,{children:[e.jsx(Q,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"گروه خدمات"}),e.jsx(de,{})]});export{je as default};
