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