import{d as j,a as b,qR as f,r as g,j as r,I as T,aM as E,U as F,qS as S,qT as A,qU as d}from"./index-60657852.js";import{c as C,b as q,u as v}from"./index.esm-509a598d.js";import{o as w}from"./yup-75ad371b.js";import"./GenericThumbnailView-f8b17afa.js";import{F as I}from"./FormInput-6b018fe9.js";import"./componentStyles-19763afb.js";import"./ScrollableList-ef4c85dc.js";import"./TextArea-d897dbf9.js";import{D as U,a as B}from"./DialogContent-d5183bd6.js";import{D as L}from"./DialogTitle-66c21479.js";import{D as $}from"./DialogContentText-e3f3f7dd.js";import{D as k}from"./DialogActions-1dfa5a01.js";import{L as c}from"./LoadingButton-c619bdb5.js";const Y=({modal:a,setModalOpen:P,closeModal:i})=>{const t=j(),{expenditureType:{selectedData:e,pageParams:p,loading:m}}=b(o=>f(o)),l=C().shape({name:q().required("Please enter Type of Expenditure").trim().matches(/^[a-zA-Z0-9 ]*$/,"expenditureType name should not contain special characters")});g.useEffect(()=>{a?n({name:(e==null?void 0:e.name)||""}):n()},[a,e]);const{control:u,handleSubmit:x,reset:n}=v({resolver:w(l),values:{name:e!=null&&e.name?e==null?void 0:e.name:""}}),h=o=>{if(e!=null&&e.id){const s={obj:{id:e!=null&&e.id?e==null?void 0:e.id:"",name:o.name},pageParams:p,clearDataFn:()=>{i(),t(d({})),n()}};t(A(s))}else{const s={obj:{name:o.name},pageParams:p,clearDataFn:()=>{i(),t(d({})),n()}};t(S(s))}};return r.jsx(r.Fragment,{children:r.jsxs(U,{open:a,onClose:i,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[r.jsxs(L,{sx:{bgcolor:"primary.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[e!=null&&e.id?"Update ":"Add ","Type of Expenditure",r.jsx(T,{onClick:i,children:r.jsx(E,{color:"white"})})]}),r.jsx(B,{sx:{px:"24px",pt:"12px !important",pb:0},children:r.jsx($,{id:"alert-dialog-description",sx:{width:500},children:r.jsxs("form",{style:{width:"100%"},onSubmit:x(h),children:[r.jsx(I,{name:"name",label:"Name",type:"text",required:!0,placeholder:"Enter ExpenditureType here...",control:u}),r.jsxs(k,{sx:{p:2},children:[r.jsx(F,{onClick:i,variant:"outlined",color:"secondary",children:"Cancel"}),e!=null&&e.id?r.jsx(c,{variant:"contained",type:"submit",color:"primary",loading:m,autoFocus:!0,children:"Update"}):r.jsx(c,{variant:"contained",type:"submit",color:"primary",loading:m,autoFocus:!0,children:"Submit"})]})]})})})]})})};export{Y as A};
