import{d as b,a as f,pg as y,r as k,j as a,I as S,aK as A,R as F,ph as w,pi as C,pj as c}from"./index-c121b02d.js";import{c as v,b as x,u as R}from"./index.esm-0c6778ff.js";import{o as E}from"./yup-1361ecb6.js";import"./GenericThumbnailView-77114fcb.js";import{F as I}from"./FormInput-c000e22e.js";import"./componentStyles-2d610038.js";import"./ScrollableList-dc408f1e.js";import{T}from"./TextArea-dfbfc4f6.js";import{D as B,a as L}from"./DialogContent-caa035c8.js";import{D as $}from"./DialogTitle-9f04a88b.js";import{D as q}from"./DialogContentText-e68ec1be.js";import{D as P}from"./DialogActions-1901dd11.js";import{L as u}from"./LoadingButton-66be9360.js";const _=({modal:n,setModalOpen:U,closeModal:s})=>{const o=b(),{stages:{selectedData:r,pageParams:m,loading:p}}=f(i=>y(i)),d=v().shape({name:x().required("Please enter stage name").trim().matches(/^[a-zA-Z0-9 ]*$/,"stages name should not contain special characters"),remarks:x().trim()});k.useEffect(()=>{n?e({name:(r==null?void 0:r.name)||"",remarks:(r==null?void 0:r.remarks)||""}):e()},[n,r]);const{control:l,handleSubmit:h,reset:e}=R({resolver:E(d),values:{name:r!=null&&r.name?r==null?void 0:r.name:"",remarks:r!=null&&r.remarks?r==null?void 0:r.remarks:""}}),g=i=>{if(r!=null&&r.id){const t={obj:{id:r!=null&&r.id?r==null?void 0:r.id:"",name:i.name,remarks:i.remarks},pageParams:m,clearDataFn:()=>{s(),o(c({})),e()}};o(C(t))}else{const t={obj:{name:i.name,remarks:i.remarks},pageParams:m,clearDataFn:()=>{s(),o(c({})),e()}};o(w(t))}};return a.jsx(a.Fragment,{children:a.jsxs(B,{open:n,onClose:s,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[a.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:[r!=null&&r.id?"Update ":"Add ","Stage",a.jsx(S,{onClick:s,children:a.jsx(A,{color:"white"})})]}),a.jsx(L,{sx:{px:"24px",pt:"12px !important",pb:0},children:a.jsx(q,{id:"alert-dialog-description",sx:{width:500},children:a.jsxs("form",{style:{width:"100%"},onSubmit:h(g),children:[a.jsx(I,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter Stages here...",control:l}),a.jsx(T,{name:"remarks",label:"Remarks",type:"text",placeholder:"Write remarks here...",minRows:3,maxRows:5,containerSx:{display:"grid",gap:1},control:l}),a.jsxs(P,{sx:{p:2},children:[a.jsx(F,{onClick:s,variant:"outlined",color:"secondary",children:"Cancel"}),r!=null&&r.id?a.jsx(u,{variant:"contained",type:"submit",color:"primary",loading:p,autoFocus:!0,children:"Update"}):a.jsx(u,{variant:"contained",type:"submit",color:"primary",loading:p,autoFocus:!0,children:"Submit"})]})]})})})]})})};export{_ as A};
