import{d as j,a as b,q6 as f,r as g,j as r,I as T,aL as E,R as F,q7 as A,q8 as C,q9 as d}from"./index-952e178b.js";import{c as S,b as q,u as v}from"./index.esm-6feddb16.js";import{o as w}from"./yup-d92565dd.js";import"./GenericThumbnailView-4e535459.js";import{F as I}from"./FormInput-8320115a.js";import"./componentStyles-00160cc0.js";import"./ScrollableList-cd5816a8.js";import"./TextArea-ce7716c9.js";import{D as L,a as B}from"./DialogContent-4facb916.js";import{D as $}from"./DialogTitle-3aa960f8.js";import{D as k}from"./DialogContentText-54d95680.js";import{D as P}from"./DialogActions-bd200b72.js";import{L as c}from"./LoadingButton-404f8a68.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};
