import{d as b,a as f,qJ as y,r as k,j as i,I as S,aM as F,U as w,qK as A,qL as C,qM as c}from"./index-c3f592b2.js";import{c as q,b as x,u as v}from"./index.esm-70dd1c06.js";import{o as E}from"./yup-abb4a026.js";import"./GenericThumbnailView-9f1d2f81.js";import{F as I}from"./FormInput-adbf55b1.js";import"./componentStyles-b8fcedb5.js";import"./ScrollableList-ecbfc0f3.js";import{T as L}from"./TextArea-674a9ec6.js";import{D as R,a as T}from"./DialogContent-b7fc1c43.js";import{D as B}from"./DialogTitle-5d3e2030.js";import{D as U}from"./DialogContentText-c3e782dc.js";import{D as P}from"./DialogActions-6e00f4f1.js";import{L as u}from"./LoadingButton-69b28388.js";const Z=({modal:n,setModalOpen:$,closeModal:s})=>{const a=b(),{stages:{selectedData:r,pageParams:m,loading:p}}=f(o=>y(o)),d=q().shape({name:x().required("Please enter stage name").trim(),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:g,reset:e}=v({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(),a(c({})),e()}};a(C(t))}else{const t={obj:{name:o.name,remarks:o.remarks},pageParams:m,clearDataFn:()=>{s(),a(c({})),e()}};a(A(t))}};return i.jsx(i.Fragment,{children:i.jsxs(R,{open:n,onClose:s,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[i.jsxs(B,{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(T,{sx:{px:"24px",pt:"12px !important",pb:0},children:i.jsx(U,{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(L,{name:"remarks",label:"Remarks",type:"text",placeholder:"Write remarks here...",minRows:3,maxRows:5,containerSx:{display:"grid",gap:1},control:l}),i.jsxs(P,{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{Z as A};
