import{d as b,a as f,p_ as y,r as k,j as i,I as S,aL as F,R as w,p$ as A,q0 as C,q1 as c}from"./index-952e178b.js";import{c as v,b as x,u as R}from"./index.esm-6feddb16.js";import{o as q}from"./yup-d92565dd.js";import"./GenericThumbnailView-4e535459.js";import{F as E}from"./FormInput-8320115a.js";import"./componentStyles-00160cc0.js";import"./ScrollableList-cd5816a8.js";import{T as I}from"./TextArea-ce7716c9.js";import{D as L,a as T}from"./DialogContent-4facb916.js";import{D as B}from"./DialogTitle-3aa960f8.js";import{D as $}from"./DialogContentText-54d95680.js";import{D as P}from"./DialogActions-bd200b72.js";import{L as u}from"./LoadingButton-404f8a68.js";const Z=({modal:n,setModalOpen:U,closeModal:s})=>{const a=b(),{stages:{selectedData:r,pageParams:m,loading:p}}=f(o=>y(o)),d=v().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}=R({resolver:q(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(L,{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($,{id:"alert-dialog-description",sx:{width:500},children:i.jsxs("form",{style:{width:"100%"},onSubmit:g(h),children:[i.jsx(E,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter Stages here...",control:l}),i.jsx(I,{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};
