import{d as j,a as b,oN as f,r as g,j as r,I as T,aI as E,R as F,oO as A,oP as C,oQ as d}from"./index-858224db.js";import{c as S,b as v,u as w}from"./index.esm-241dec99.js";import{o as I}from"./yup-9213c3af.js";import"./GenericThumbnailView-2d7b7363.js";import{F as B}from"./FormInput-8eacbbd9.js";import"./componentStyles-107bd37e.js";import"./ScrollableList-bf78e54b.js";import"./TextArea-78cda1eb.js";import{D as L,a as P}from"./DialogContent-e06a39bc.js";import{D as $}from"./DialogTitle-6e616d34.js";import{D as k}from"./DialogContentText-a2775ca2.js";import{D as q}from"./DialogActions-825c19e9.js";import{L as c}from"./LoadingButton-4babbc5c.js";const Y=({modal:a,setModalOpen:N,closeModal:i})=>{const o=j(),{expenditureType:{selectedData:e,pageParams:p,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?t({name:(e==null?void 0:e.name)||""}):t()},[a,e]);const{control:u,handleSubmit:x,reset:t}=w({resolver:I(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(d({})),t()}};o(C(s))}else{const s={obj:{name:n.name},pageParams:p,clearDataFn:()=>{i(),o(d({})),t()}};o(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(P,{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(B,{name:"name",label:"Name",type:"text",required:!0,placeholder:"Enter ExpenditureType here...",control:u}),r.jsxs(q,{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};
