import{j as e,S as I,c as y,W as _}from"./vendor-mui-CBBEb17G.js";import{B as A}from"./index-BkhbTDKf.js";import{S as T}from"./styleServiceDetailsListContainer-Bn5_tO1d.js";import{a as i}from"./vendor-react-BBazpZul.js";import{S as h}from"./index-B0mWmapq.js";import{aX as w,ao as B,J as L,v as C,aP as j,x as v,at as k,dD as z,I as f}from"./index-IP_FWtso.js";import"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";const E=i.createContext(null),P=({children:x})=>{const{get:s,getById:d}=new h,[m,t]=i.useState(!1),[l,u]=i.useState(1),[o,c]=i.useState(50),[a,S]=i.useState(null),[r,g]=i.useState(null),[n,N]=i.useState(null),R={states:{loading:m,pageNumber:l,pageSize:o,serviceDetailsLabels:a,serviceDetailsLabel:r,selectedServiceDetailsLabel:n},actions:{setPageNumber:u,setPageSize:c,setServiceDetailsLabel:g,setSelectedServiceDetailsLabel:N},handlers:{getServiceDetailsLabels:async()=>{try{t(!0);const{data:b}=await s({PageNumber:l,PageSize:o});if(!b)return;S(b)}catch{console.log("ERROR_IN_GETTING_SERVICE_DETAILS_LABELS")}finally{t(!1)}},getServiceDetailsLabelById:async b=>{try{t(!0);const{data:D}=await d(b);if(!D)return;g(D)}catch{console.log("ERROR_IN_GETTING_SERVICE_DETAILS_LABELS")}finally{t(!1)}}}};return e.jsx(E.Provider,{value:R,children:x})},p=()=>i.useContext(E),M=()=>{const{toggle:x}=new h,{states:{loading:s,pageNumber:d,pageSize:m,serviceDetailsLabels:t},actions:{setPageNumber:l,setPageSize:u,setSelectedServiceDetailsLabel:o},handlers:{getServiceDetailsLabels:c}}=p(),a=async r=>{const{message:g}=await x(r);L.success(g),c()};i.useEffect(()=>{c()},[d,m]);const S=[{key:"name",dataIndex:"name",title:"عنوان",width:200},{key:"isDelete",dataIndex:"isDelete",title:"وضعیت",width:150,render:(r,g)=>e.jsx("div",{className:"flex justify-center items-center",children:e.jsx(B,{className:"w-[100px]",sx:{borderRadius:"20px !important",height:"25px !important"},color:r?"error":"success",onClick:()=>a(g.id),children:r?"غیرفعال":"فعال"})})}];return e.jsx(I,{className:"!h-[80dvh]",children:e.jsx(w,{rowKey:"id",loading:s,data:(t==null?void 0:t.list)||[],columns:S,pageNumber:((t==null?void 0:t.pagination.pageNumber)||1)-1,pageSize:(t==null?void 0:t.pagination.pageSize)||50,totalCount:(t==null?void 0:t.pagination.totalCount)||50,onPaginationLoad:(r,g)=>{l(r+1),u(g)},onClick:r=>o(r)})})};function O({onClose:x}){const{add:s}=new h,{handlers:{getServiceDetailsLabels:d}}=p(),[m,t]=i.useState(!1),[l,u]=i.useState(""),o=()=>{u(""),x()},c=async()=>{try{t(!0);const{message:a}=await s({name:l});L.success(a),d(),o()}catch(a){console.log("ERROR_IN_SUBMITTING_ADD_MODAL(SERVICE_DETAILS_LABEL)",a)}finally{t(!1)}};return e.jsx(C,{title:"افزودن گروه برچسب",onClose:o,maxWidth:"xs",children:e.jsxs(y,{className:"!py-3",children:[e.jsx(j,{label:"عنوان",value:l,onChange:a=>u(a)}),e.jsx(v,{loading:m,onClose:o,onSubmit:c})]})})}function G({onClose:x}){const{update:s}=new h,{states:{serviceDetailsLabel:d},handlers:{getServiceDetailsLabels:m}}=p(),[t,l]=i.useState(!1),[u,o]=i.useState(d.name),c=()=>{o(""),x()},a=async()=>{try{if(!d)return;l(!0);const{message:S}=await s({id:d.id,name:u});L.success(S),m(),c()}catch(S){console.log("ERROR_IN_SUBMITTING_EDIT_MODAL(SERVICE_DETAILS_LABEL)",S)}finally{l(!1)}};return e.jsx(C,{title:"ویرایش گروه برچسب",onClose:c,maxWidth:"xs",children:e.jsxs(y,{className:"!py-3",children:[e.jsx(j,{label:"عنوان",value:u,onChange:S=>o(S)}),e.jsx(v,{loading:t,onClose:c,onSubmit:a})]})})}const U=()=>{const{remove:x}=new h,{states:{selectedServiceDetailsLabel:s,serviceDetailsLabel:d},actions:{setSelectedServiceDetailsLabel:m,setServiceDetailsLabel:t},handlers:{getServiceDetailsLabels:l,getServiceDetailsLabelById:u}}=p(),o=k(),[c,a]=i.useState({add:!1,edit:!1}),S=async()=>{s&&(a(n=>({...n,edit:!0})),u(s.id),m(null))},r=async()=>{s&&o({content:"آیا از حذف این آیتم مطمئنید؟"}).then(async()=>{await x(s.id),l(),m(null)})},g=[{title:"افزودن",icon:e.jsx(f.AddIcon,{fontSize:"large",color:"success"}),onClick:()=>a(n=>({...n,add:!0})),disabled:!1},{title:"ویرایش",icon:e.jsx(f.EditIcon,{fontSize:"large",color:s?"primary":"disabled"}),onClick:S,disabled:!s},{title:"حذف",icon:e.jsx(f.DeleteIcon,{fontSize:"large",color:s?"error":"disabled"}),onClick:r,disabled:!s},{title:"بازنشانی",icon:e.jsx(f.RefreshIcon,{fontSize:"large",color:"primary"}),onClick:l,disabled:!1}];return e.jsxs(I,{direction:"row",justifyContent:"start",alignItems:"center",spacing:1,children:[g.map(n=>e.jsx(z,{disabled:n.disabled,onClick:n.onClick,children:e.jsx(_,{placement:"top",title:e.jsx("h1",{className:"text-sm",children:n.title}),children:n.icon})})),c.add&&e.jsx(O,{onClose:()=>a(n=>({...n,add:!1}))}),c.edit&&d&&e.jsx(G,{onClose:()=>{a(n=>({...n,edit:!1})),t(null)}})]})},Z=()=>e.jsxs(T,{className:"bg-gray-50 space-y-2",children:[e.jsx(A,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"گروه برچسب"}),e.jsxs(P,{children:[e.jsx(U,{}),e.jsx(M,{})]})]});export{Z as ServiceDetailsLabelPage};
