import{d as j,a as b,od as f,r as y,j as r,I as S,ax as F,z as A,oe as C,of as v,og as c}from"./index-d895656a.js";import{c as w,b as E,u as I}from"./index.esm-1087b2f3.js";import{o as B}from"./yup-9573aa79.js";import"./GenericThumbnailView-532ea2d7.js";import{F as L}from"./FormInput-9b5da280.js";import"./componentStyles-866300fe.js";import"./ScrollableList-e2b22048.js";import"./TextArea-fb0d0821.js";import{D as $,a as k}from"./DialogContent-4ce43512.js";import{D as q}from"./DialogTitle-738ca272.js";import{D as z}from"./DialogContentText-8b9b0e0c.js";import{D as P}from"./DialogActions-7b82f6f6.js";import{L as l}from"./LoadingButton-c8915ab4.js";const Y=({modal:s,setModalOpen:T,closeModal:t})=>{const a=j(),{stages:{selectedData:o,pageParams:m,loading:p}}=b(e=>f(e)),d=w().shape({name:E().required("Please enter stage name").trim().matches(/^[a-zA-Z0-9 ]*$/,"stages name should not contain special characters")});y.useEffect(()=>{s?i({name:(o==null?void 0:o.name)||""}):i()},[s,o]);const{control:u,handleSubmit:x,reset:i}=I({resolver:B(d),values:{name:o!=null&&o.name?o==null?void 0:o.name:""}}),g=e=>{if(o!=null&&o.id){const n={obj:{id:o!=null&&o.id?o==null?void 0:o.id:"",name:e.name},pageParams:m,clearDataFn:()=>{t(),a(c({})),i()}};a(v(n))}else{const n={obj:{name:e.name},pageParams:m,clearDataFn:()=>{t(),a(c({})),i()}};a(C(n))}};return r.jsx(r.Fragment,{children:r.jsxs($,{open:s,onClose:t,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[r.jsxs(q,{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(k,{sx:{px:"24px",pt:"12px !important",pb:0},children:r.jsx(z,{id:"alert-dialog-description",sx:{width:500},children:r.jsxs("form",{style:{width:"100%"},onSubmit:x(g),children:[r.jsx(L,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter Stages here...",control:u}),r.jsxs(P,{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};
