import{d as b,a as f,pj as k,r as y,j as i,I as S,aK as F,R as w,pk as A,pl as C,pm as c}from"./index-aa25c5ff.js";import{c as v,b as x,u as R}from"./index.esm-a7f661dc.js";import{o as E}from"./yup-72cc4918.js";import"./GenericThumbnailView-e0343bac.js";import{F as I}from"./FormInput-dc74a5d8.js";import"./componentStyles-e32842f3.js";import"./ScrollableList-9498bc37.js";import{T}from"./TextArea-d1a16eb1.js";import{D as B}from"./Dialog-049271f6.js";import{D as L}from"./DialogTitle-7a3842b8.js";import{D as q}from"./DialogContent-f207f33c.js";import{D as P}from"./DialogContentText-70face94.js";import{D as U}from"./DialogActions-2338d733.js";import{L as u}from"./LoadingButton-bec71809.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};
