import{j as e,c as R,S as c,W as x}from"./vendor-mui-CBBEb17G.js";import{B as z}from"./index-DQbmBtLN.js";import{a as r}from"./vendor-react-BBazpZul.js";import{aO as A,v,by as B,aP as E,x as F,at as L,c5 as O,dD as h,I as p,aX as W,J as g,z as q}from"./index-DdWwwZXu.js";import{P as K}from"./index-m8j3hXgZ.js";import{S as M}from"./index-CDArk_1r.js";import"./vendor-utils-BveVE6Uf.js";import"./vendor-charts-tGnAgELZ.js";const J=({defaultValue:o,onClose:i,onSubmit:f,loading:j})=>{const{control:y,handleSubmit:d,formState:{errors:a}}=A({defaultValues:o??void 0}),S=async n=>{await f(n.name),i()};return e.jsxs(v,{title:o?"ویرایش نوع پرداخت":"افزودن نوع پرداخت",onClose:i,maxWidth:"xs",children:[e.jsx(R,{className:"m-1 !p-2",children:e.jsx(c,{component:"form",children:e.jsx(B,{name:"name",control:y,rules:{required:!0},render:({field:{onChange:n,value:m}})=>e.jsx(E,{label:"عنوان",fullWidth:!0,error:!!a.name,value:m,onChange:n,required:!0})})})}),e.jsx(F,{onClose:i,onSubmit:d(S),loading:j})]})},Q=()=>{const{addPaymentType:o,deletePaymentType:i,getPaymentType:f,updatePaymentType:j}=new K,y=L(),[d,a]=r.useState(!1),[S,n]=r.useState(!1),[m,I]=r.useState([]),[w,b]=r.useState([]),[s,P]=r.useState(null),l=async()=>{try{a(!0);const{data:t}=await f();t&&I(t),t&&b(t)}finally{a(!1)}},T=t=>{m.length&&b(m.filter(u=>u.name.includes(t)||u.id.toString().includes(t)))},C=async t=>{try{if(a(!0),s){const{message:N}=await j({name:t,id:s.id});g.success(N),l();return}const{message:u}=await o({name:t});g.success(u),l()}finally{a(!1)}},D=()=>{try{if(a(!0),!s)return;y({content:"آیا از حذف این مورد اطمینان دارید؟"}).then(async()=>{const{message:t}=await i(s.id);g.success(t),l()}).catch(()=>{})}finally{a(!1)}};r.useEffect(()=>{l()},[]);const k=[{title:"کد",key:"id",dataIndex:"id",width:70,render:t=>q(t??0)},{title:"عنوان",key:"name",dataIndex:"name",width:250}];return e.jsxs(c,{spacing:1,p:1,className:"h-full",children:[e.jsxs(c,{direction:{xs:"column",md:"row"},alignItems:{xs:"start",md:"center"},spacing:1,children:[e.jsx(O,{onChange:T}),e.jsxs(c,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(x,{title:e.jsx("h1",{className:"text-sm",children:"افزودن"}),placement:"top",children:e.jsx(h,{onClick:()=>n(!0),children:e.jsx(p.AddIcon,{fontSize:"large",color:"success"})})}),e.jsx(x,{title:e.jsx("h1",{className:"text-sm",children:"ویرایش"}),placement:"top",children:e.jsx(h,{onClick:()=>s&&n(!0),disabled:!s,children:e.jsx(p.EditIcon,{fontSize:"large",color:s?"primary":"disabled"})})}),e.jsx(x,{title:e.jsx("h1",{className:"text-sm",children:"حذف"}),placement:"top",children:e.jsx(h,{onClick:()=>s&&D(),disabled:!s,children:e.jsx(p.DeleteIcon,{fontSize:"large",color:s?"error":"disabled"})})}),e.jsx(x,{title:e.jsx("h1",{className:"text-sm",children:"تازه سازی"}),placement:"top",children:e.jsx(h,{onClick:()=>l(),children:e.jsx(p.RefreshIcon,{fontSize:"large",color:"info"})})})]})]}),e.jsx(c,{className:"h-[76dvh]",children:e.jsx(W,{columns:k,data:w,rowKey:"id",loading:d,onClick:t=>P(t)})}),S&&e.jsx(J,{onClose:()=>n(!1),defaultValue:s,loading:d,onSubmit:C})]})},$=()=>e.jsxs(M,{children:[e.jsx(z,{prevRoutes:[{path:"/",title:"داشبورد"}],currentRoute:"نوع پرداخت"}),e.jsx(Q,{})]});export{$ as default};
