import{d as b,a as f,qy as y,r as k,j as i,I as S,aL as A,R as F,qz as w,qA as C,qB as c}from"./index-e79f7aad.js";import{c as q,b as x,u as v}from"./index.esm-1ca67d65.js";import{o as R}from"./yup-96f14780.js";import"./GenericThumbnailView-8a83a30c.js";import{F as B}from"./FormInput-07daa19d.js";import"./componentStyles-7718fc5e.js";import"./ScrollableList-5929779e.js";import{T as E}from"./TextArea-ec29d1d5.js";import{D as I,a as L}from"./DialogContent-6a297cef.js";import{D as T}from"./DialogTitle-62595023.js";import{D as P}from"./DialogContentText-0c5306f9.js";import{D as U}from"./DialogActions-edd1d02f.js";import{L as u}from"./LoadingButton-2d3ef2e0.js";const _=({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:R(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(w(t))}};return i.jsx(i.Fragment,{children:i.jsxs(I,{open:n,onClose:s,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[i.jsxs(T,{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(A,{color:"white"})})]}),i.jsx(L,{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(B,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter Stages here...",control:l}),i.jsx(E,{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(F,{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{_ as A};
