import{b,a as j,vB as f,r as g,j as r,I as E,ec as T,K as v,vC as C,vD as F,vE as c}from"./index-60a3c753.js";import{c as A,b as S}from"./index.esm-62d6b2f7.js";import{o as w}from"./yup-92678dde.js";import{u as B}from"./index.esm-c494934a.js";import"./componentStyles-7753bbb9.js";import{F as I}from"./FormInput-74e2c4d2.js";/* empty css                   */import"./ScrollableList-1962b023.js";import{D as L,a as $}from"./DialogContent-89e21f2e.js";import{D as k}from"./DialogTitle-fe69da5c.js";import{D as q}from"./DialogContentText-6688bd59.js";import{D as P}from"./DialogActions-e754942c.js";import{L as d}from"./LoadingButton-3975ddf9.js";const Y=({modal:a,setModalOpen:U,closeModal:i})=>{const o=b(),{expenditureType:{selectedData:e,pageParams:p,loading:m}}=j(n=>f(n)),l=A().shape({name:S().required("Please enter Type of Expenditure").trim().matches(/^[a-zA-Z0-9 ]*$/,"expenditureType name should not contain special characters")});g.useEffect(()=>{a?t({name:(e==null?void 0:e.name)||""}):t()},[a,e]);const{control:u,handleSubmit:x,reset:t}=B({resolver:w(l),values:{name:e!=null&&e.name?e==null?void 0:e.name:""}}),h=n=>{if(e!=null&&e.id){const s={obj:{id:e!=null&&e.id?e==null?void 0:e.id:"",name:n.name},pageParams:p,clearDataFn:()=>{i(),o(c({})),t()}};o(F(s))}else{const s={obj:{name:n.name},pageParams:p,clearDataFn:()=>{i(),o(c({})),t()}};o(C(s))}};return r.jsx(r.Fragment,{children:r.jsxs(L,{open:a,onClose:i,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[r.jsxs(k,{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(E,{onClick:i,children:r.jsx(T,{color:"white"})})]}),r.jsx($,{sx:{px:"24px",pt:"12px !important",pb:0},children:r.jsx(q,{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(P,{sx:{p:2},children:[r.jsx(v,{onClick:i,variant:"outlined",color:"secondary",children:"Cancel"}),e!=null&&e.id?r.jsx(d,{variant:"contained",type:"submit",color:"primary",loading:m,autoFocus:!0,children:"Update"}):r.jsx(d,{variant:"contained",type:"submit",color:"primary",loading:m,autoFocus:!0,children:"Submit"})]})]})})})]})})};export{Y as A};
