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-e0c07a84.js";import{c as v,b as x,u as R}from"./index.esm-79617ba5.js";import{o as E}from"./yup-74a95d85.js";import"./GenericThumbnailView-d192caf7.js";import{F as I}from"./FormInput-7bb37f2a.js";import"./componentStyles-5432a72d.js";import"./ScrollableList-874c742d.js";import{T}from"./TextArea-e9886f56.js";import{D as B,a as L}from"./DialogContent-bfc00e3a.js";import{D as $}from"./DialogTitle-d1ec1f1a.js";import{D as q}from"./DialogContentText-c88b94b0.js";import{D as P}from"./DialogActions-7f92619e.js";import{L as u}from"./LoadingButton-f9561377.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};
