import{d as b,a as f,pi as k,r as y,j as i,I as S,aK as F,R as w,pj as A,pk as C,pl as c}from"./index-e6164346.js";import{c as v,b as x,u as R}from"./index.esm-0a041314.js";import{o as E}from"./yup-5fd5d57b.js";import"./GenericThumbnailView-80c6fd98.js";import{F as I}from"./FormInput-859198ec.js";import"./componentStyles-00385170.js";import"./ScrollableList-5a17e8f4.js";import{T}from"./TextArea-f5c200de.js";import{D as B}from"./Dialog-2e8a8e2e.js";import{D as L}from"./DialogTitle-8757f50f.js";import{D as q}from"./DialogContent-f10d6731.js";import{D as P}from"./DialogContentText-027be15d.js";import{D as U}from"./DialogActions-31bec80e.js";import{L as u}from"./LoadingButton-bce4d1bf.js";const M=({modal:n,setModalOpen:$,closeModal:s})=>{const e=b(),{stages:{selectedData:r,pageParams:m,loading:p}}=f(o=>k(o)),d=v().shape({name:x().required("Please enter stage name").trim(),remarks:x().trim()});y.useEffect(()=>{n?a({name:(r==null?void 0:r.name)||"",remarks:(r==null?void 0:r.remarks)||""}):a()},[n,r]);const{control:l,handleSubmit:g,reset:a}=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:""}}),h=o=>{if(r!=null&&r.id){const t={obj:{id:r!=null&&r.id?r==null?void 0:r.id:"",name:o.name,remarks:o.remarks},pageParams:m,clearDataFn:()=>{s(),e(c({})),a()}};e(C(t))}else{const t={obj:{name:o.name,remarks:o.remarks},pageParams:m,clearDataFn:()=>{s(),e(c({})),a()}};e(A(t))}};return i.jsx(i.Fragment,{children:i.jsxs(B,{open:n,onClose:s,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[i.jsxs(L,{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",i.jsx(S,{onClick:s,children:i.jsx(F,{color:"white"})})]}),i.jsx(q,{sx:{px:"24px",pt:"12px !important",pb:0},children:i.jsx(P,{id:"alert-dialog-description",sx:{width:500},children:i.jsxs("form",{style:{width:"100%"},onSubmit:g(h),children:[i.jsx(I,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter Stages here...",control:l}),i.jsx(T,{name:"remarks",label:"Remarks",type:"text",placeholder:"Write remarks here...",minRows:3,maxRows:5,containerSx:{display:"grid",gap:1},control:l}),i.jsxs(U,{sx:{p:2},children:[i.jsx(w,{onClick:s,variant:"outlined",color:"secondary",children:"Cancel"}),r!=null&&r.id?i.jsx(u,{variant:"contained",type:"submit",color:"primary",loading:p,autoFocus:!0,children:"Update"}):i.jsx(u,{variant:"contained",type:"submit",color:"primary",loading:p,autoFocus:!0,children:"Submit"})]})]})})})]})})};export{M as A};
