import{d as j,a as b,ps as f,r as g,j as r,I as T,aK as E,R as F,pt as v,pu as A,pv as d}from"./index-5ae5cc5e.js";import{c as C,b as S,u as w}from"./index.esm-bd37e938.js";import{o as I}from"./yup-86a48159.js";import"./GenericThumbnailView-fac7773c.js";import{F as B}from"./FormInput-77541d96.js";import"./componentStyles-7d84c389.js";import"./ScrollableList-2ee889f8.js";import"./TextArea-20f097f8.js";import{D as L,a as $}from"./DialogContent-e2578cbd.js";import{D as k}from"./DialogTitle-4a5aec12.js";import{D as q}from"./DialogContentText-bc10bf8d.js";import{D as P}from"./DialogActions-ad26e3d6.js";import{L as c}from"./LoadingButton-d465030d.js";const Y=({modal:a,setModalOpen:R,closeModal:i})=>{const t=j(),{expenditureType:{selectedData:e,pageParams:s,loading:m}}=b(o=>f(o)),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?n({name:(e==null?void 0:e.name)||""}):n()},[a,e]);const{control:u,handleSubmit:x,reset:n}=w({resolver:I(l),values:{name:e!=null&&e.name?e==null?void 0:e.name:""}}),h=o=>{if(e!=null&&e.id){const p={obj:{id:e!=null&&e.id?e==null?void 0:e.id:"",name:o.name},pageParams:s,clearDataFn:()=>{i(),t(d({})),n()}};t(A(p))}else{const p={obj:{name:o.name},pageParams:s,clearDataFn:()=>{i(),t(d({})),n()}};t(v(p))}};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(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};
