import{d as j,a as b,on as f,r as y,j as r,I as S,aI as F,R as A,oo as C,op as v,oq as c}from"./index-dc933734.js";import{c as w,b as I,u as E}from"./index.esm-288e984c.js";import{o as q}from"./yup-5b2e0cf9.js";import"./GenericThumbnailView-69a8725b.js";import{F as B}from"./FormInput-58d4b01b.js";import"./componentStyles-4df963a1.js";import"./ScrollableList-c8354e44.js";import"./TextArea-80ac5c9b.js";import{D as L,a as $}from"./DialogContent-d9f48895.js";import{D as k}from"./DialogTitle-4ec33ac0.js";import{D as P}from"./DialogContentText-e0ace713.js";import{D as R}from"./DialogActions-9dacec58.js";import{L as l}from"./LoadingButton-2e968ec8.js";const Y=({modal:n,setModalOpen:T,closeModal:t})=>{const a=j(),{stages:{selectedData:o,pageParams:m,loading:p}}=b(e=>f(e)),d=w().shape({name:I().required("Please enter stage name").trim().matches(/^[a-zA-Z0-9 ]*$/,"stages name should not contain special characters")});y.useEffect(()=>{n?i({name:(o==null?void 0:o.name)||""}):i()},[n,o]);const{control:u,handleSubmit:x,reset:i}=E({resolver:q(d),values:{name:o!=null&&o.name?o==null?void 0:o.name:""}}),h=e=>{if(o!=null&&o.id){const s={obj:{id:o!=null&&o.id?o==null?void 0:o.id:"",name:e.name},pageParams:m,clearDataFn:()=>{t(),a(c({})),i()}};a(v(s))}else{const s={obj:{name:e.name},pageParams:m,clearDataFn:()=>{t(),a(c({})),i()}};a(C(s))}};return r.jsx(r.Fragment,{children:r.jsxs(L,{open:n,onClose:t,"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:[o!=null&&o.id?"Update ":"Add ","Stage",r.jsx(S,{onClick:t,children:r.jsx(F,{color:"white"})})]}),r.jsx($,{sx:{px:"24px",pt:"12px !important",pb:0},children:r.jsx(P,{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",required:!0,type:"text",placeholder:"Enter Stages here...",control:u}),r.jsxs(R,{sx:{p:2},children:[r.jsx(A,{onClick:t,variant:"outlined",color:"secondary",children:"Cancel"}),o!=null&&o.id?r.jsx(l,{variant:"contained",type:"submit",color:"primary",loading:p,autoFocus:!0,children:"Update"}):r.jsx(l,{variant:"contained",type:"submit",color:"primary",loading:p,autoFocus:!0,children:"Submit"})]})]})})})]})})};export{Y as A};
