import{d as b,a as j,p8 as f,r as y,j as t,I as S,aK as F,R as A,p9 as C,pa as v,pb as c}from"./index-458d5762.js";import{c as w,b as E,u as I}from"./index.esm-b1b14098.js";import{o as B}from"./yup-536c503d.js";import"./GenericThumbnailView-3cd8dbb5.js";import{F as L}from"./FormInput-3d74947b.js";import"./componentStyles-56425874.js";import"./ScrollableList-ba92364a.js";import"./TextArea-233680fc.js";import{D as $,a as k}from"./DialogContent-2b2d5db0.js";import{D as q}from"./DialogTitle-bda4183d.js";import{D as P}from"./DialogContentText-f6501c39.js";import{D as R}from"./DialogActions-38a5ba62.js";import{L as l}from"./LoadingButton-e2205495.js";const Y=({modal:s,setModalOpen:T,closeModal:a})=>{const o=b(),{stages:{selectedData:r,pageParams:m,loading:p}}=j(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:(r==null?void 0:r.name)||""}):i()},[s,r]);const{control:u,handleSubmit:x,reset:i}=I({resolver:B(d),values:{name:r!=null&&r.name?r==null?void 0:r.name:""}}),h=e=>{if(r!=null&&r.id){const n={obj:{id:r!=null&&r.id?r==null?void 0:r.id:"",name:e.name},pageParams:m,clearDataFn:()=>{a(),o(c({})),i()}};o(v(n))}else{const n={obj:{name:e.name},pageParams:m,clearDataFn:()=>{a(),o(c({})),i()}};o(C(n))}};return t.jsx(t.Fragment,{children:t.jsxs($,{open:s,onClose:a,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[t.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:[r!=null&&r.id?"Update ":"Add ","Stage",t.jsx(S,{onClick:a,children:t.jsx(F,{color:"white"})})]}),t.jsx(k,{sx:{px:"24px",pt:"12px !important",pb:0},children:t.jsx(P,{id:"alert-dialog-description",sx:{width:500},children:t.jsxs("form",{style:{width:"100%"},onSubmit:x(h),children:[t.jsx(L,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter Stages here...",control:u}),t.jsxs(R,{sx:{p:2},children:[t.jsx(A,{onClick:a,variant:"outlined",color:"secondary",children:"Cancel"}),r!=null&&r.id?t.jsx(l,{variant:"contained",type:"submit",color:"primary",loading:p,autoFocus:!0,children:"Update"}):t.jsx(l,{variant:"contained",type:"submit",color:"primary",loading:p,autoFocus:!0,children:"Submit"})]})]})})})]})})};export{Y as A};
