import{d as j,a as b,pq as f,r as g,j as r,I as T,aK as E,R as F,pr as A,ps as C,pt as d}from"./index-e6164346.js";import{c as S,b as v,u as w}from"./index.esm-0a041314.js";import{o as I}from"./yup-5fd5d57b.js";import"./GenericThumbnailView-80c6fd98.js";import{F as q}from"./FormInput-859198ec.js";import"./componentStyles-00385170.js";import"./ScrollableList-5a17e8f4.js";import"./TextArea-f5c200de.js";import{D as B}from"./Dialog-2e8a8e2e.js";import{D as L}from"./DialogTitle-8757f50f.js";import{D as $}from"./DialogContent-f10d6731.js";import{D as k}from"./DialogContentText-027be15d.js";import{D as P}from"./DialogActions-31bec80e.js";import{L as c}from"./LoadingButton-bce4d1bf.js";const _=({modal:a,setModalOpen:R,closeModal:i})=>{const t=j(),{expenditureType:{selectedData:e,pageParams:s,loading:m}}=b(n=>f(n)),l=S().shape({name:v().required("Please enter Type of Expenditure").trim().matches(/^[a-zA-Z0-9 ]*$/,"expenditureType name should not contain special characters")});g.useEffect(()=>{a?o({name:(e==null?void 0:e.name)||""}):o()},[a,e]);const{control:u,handleSubmit:x,reset:o}=w({resolver:I(l),values:{name:e!=null&&e.name?e==null?void 0:e.name:""}}),h=n=>{if(e!=null&&e.id){const p={obj:{id:e!=null&&e.id?e==null?void 0:e.id:"",name:n.name},pageParams:s,clearDataFn:()=>{i(),t(d({})),o()}};t(C(p))}else{const p={obj:{name:n.name},pageParams:s,clearDataFn:()=>{i(),t(d({})),o()}};t(A(p))}};return r.jsx(r.Fragment,{children:r.jsxs(B,{open:a,onClose:i,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[r.jsxs(L,{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(k,{id:"alert-dialog-description",sx:{width:500},children:r.jsxs("form",{style:{width:"100%"},onSubmit:x(h),children:[r.jsx(q,{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{_ as A};
