import{b,a as j,vw as f,r as g,j as r,I as T,ec as E,K as v,vx as F,vy as A,vz as c}from"./index-76d4793e.js";import{c as C,b as S}from"./index.esm-ad8a7c9f.js";import{o as w}from"./yup-688ec4f6.js";import{u as I}from"./index.esm-3adfd9f7.js";import"./componentStyles-0803b39e.js";import{F as B}from"./FormInput-8f40ded1.js";/* empty css                   */import"./ScrollableList-4dae3697.js";import{D as L,a as $}from"./DialogContent-7bd8dd8f.js";import{D as k}from"./DialogTitle-71dd5b3a.js";import{D as q}from"./DialogContentText-7642f81f.js";import{D as z}from"./DialogActions-5a5e1db9.js";import{L as d}from"./LoadingButton-89ba2db7.js";const Y=({modal:a,setModalOpen:P,closeModal:i})=>{const o=b(),{expenditureType:{selectedData:e,pageParams:p,loading:m}}=j(n=>f(n)),l=C().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}=I({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(A(s))}else{const s={obj:{name:n.name},pageParams:p,clearDataFn:()=>{i(),o(c({})),t()}};o(F(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(T,{onClick:i,children:r.jsx(E,{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(B,{name:"name",label:"Name",type:"text",required:!0,placeholder:"Enter ExpenditureType here...",control:u}),r.jsxs(z,{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};
