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-e972fa8e.js";import{c as v,b as x,u as R}from"./index.esm-b3c20f6d.js";import{o as E}from"./yup-b3178c01.js";import"./GenericThumbnailView-38007944.js";import{F as I}from"./FormInput-dbaa88c2.js";import"./componentStyles-7142291f.js";import"./ScrollableList-4768c2b7.js";import{T}from"./TextArea-6c7f39e1.js";import{D as B,a as L}from"./DialogContent-51a7b314.js";import{D as $}from"./DialogTitle-6bcbc606.js";import{D as q}from"./DialogContentText-1562904b.js";import{D as P}from"./DialogActions-122de1b4.js";import{L as u}from"./LoadingButton-1312b0f8.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};
