import{d as j,a as b,qG as f,r as g,j as r,I as T,aL as E,R as F,qH as A,qI as C,qJ as d}from"./index-e79f7aad.js";import{c as S,b as q,u as v}from"./index.esm-1ca67d65.js";import{o as w}from"./yup-96f14780.js";import"./GenericThumbnailView-8a83a30c.js";import{F as I}from"./FormInput-07daa19d.js";import"./componentStyles-7718fc5e.js";import"./ScrollableList-5929779e.js";import"./TextArea-ec29d1d5.js";import{D as L,a as B}from"./DialogContent-6a297cef.js";import{D as $}from"./DialogTitle-62595023.js";import{D as k}from"./DialogContentText-0c5306f9.js";import{D as P}from"./DialogActions-edd1d02f.js";import{L as c}from"./LoadingButton-2d3ef2e0.js";const Y=({modal:a,setModalOpen:R,closeModal:i})=>{const t=j(),{expenditureType:{selectedData:e,pageParams:p,loading:m}}=b(o=>f(o)),l=S().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(C(s))}else{const s={obj:{name:o.name},pageParams:p,clearDataFn:()=>{i(),t(d({})),n()}};t(A(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($,{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(k,{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(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};
