import{b as f,a as v,vs as S,r as F,j as r,I as q,ec as A,Q as C,K as w,vt as P,vu as L,vv as d}from"./index-76d4793e.js";import{c as u,b as x,a as $}from"./index.esm-ad8a7c9f.js";import{o as B}from"./yup-688ec4f6.js";import{u as I}from"./index.esm-3adfd9f7.js";import"./componentStyles-0803b39e.js";import{F as k}from"./FormInput-8f40ded1.js";/* empty css                   */import"./ScrollableList-4dae3697.js";import{S as z}from"./SelectComponent-3c1140e6.js";import{D as N,a as T}from"./DialogContent-7bd8dd8f.js";import{D as U}from"./DialogTitle-71dd5b3a.js";import{D as E}from"./DialogContentText-7642f81f.js";import{D as K}from"./DialogActions-5a5e1db9.js";import{L as y}from"./LoadingButton-89ba2db7.js";const re=({modal:o,setModalOpen:Q,closeModal:a})=>{const i=f(),{stages:{selectedData:e,pageParams:m,loading:l}}=v(t=>S(t)),h=u().shape({name:x().required("Please enter stage name").trim().matches(/^[a-zA-Z0-9 ]*$/,"stages name should not contain special characters"),type:u({label:x().required("Please select screen type"),value:$().required("Please select screen type")}).nullable().required("Please select screen type")});F.useEffect(()=>{o?s({name:(e==null?void 0:e.name)||"",type:e!=null&&e.type?{label:e==null?void 0:e.type_name,value:Number(e==null?void 0:e.type)}:void 0}):s()},[o,e]);const{control:c,handleSubmit:b,reset:s}=I({resolver:B(h),defaultValues:{name:"",type:void 0}}),g=t=>{if(e!=null&&e.id){const p={obj:{id:e!=null&&e.id?e==null?void 0:e.id:"",name:t.name,type:t.type.value},pageParams:m,clearDataFn:()=>{a(),i(d({})),s()}};i(L(p))}else{const p={obj:{name:t.name,type:t.type.value},pageParams:m,clearDataFn:()=>{a(),i(d({})),s()}};i(P(p))}},n=[{name:"Lead",id:1},{name:"Tender",id:2},{name:"Project",id:3}];return r.jsx(r.Fragment,{children:r.jsxs(N,{open:o,onClose:a,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[r.jsxs(U,{sx:{bgcolor:"primary.main",color:"white",p:1,px:2,display:"flex",alignItems:"center",justifyContent:"space-between"},variant:"h4",id:"alert-dialog-title",children:[e!=null&&e.id?"Update ":"Add ","Stage",r.jsx(q,{onClick:a,children:r.jsx(A,{color:"white"})})]}),r.jsx(T,{sx:{px:"24px",pt:"12px !important",pb:0},children:r.jsx(E,{id:"alert-dialog-description",sx:{width:500},children:r.jsxs("form",{style:{width:"100%"},onSubmit:b(g),children:[r.jsx(C,{size:{xs:12,sm:6},children:r.jsx(z,{name:"type",label:"Screen Type",control:c,required:!0,options:n==null?void 0:n.map(t=>({id:t.id,name:t.name}))})}),r.jsx(k,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter Stages here...",control:c}),r.jsxs(K,{sx:{p:2},children:[r.jsx(w,{onClick:a,variant:"outlined",color:"secondary",children:"Cancel"}),e!=null&&e.id?r.jsx(y,{variant:"contained",type:"submit",color:"primary",loading:l,autoFocus:!0,children:"Update"}):r.jsx(y,{variant:"contained",type:"submit",color:"primary",loading:l,autoFocus:!0,children:"Submit"})]})]})})})]})})};export{re as A};
