import{b as f,a as v,vx as S,r as F,j as r,I as A,ec as q,Q as C,K as w,vy as P,vz as L,vA as d}from"./index-60a3c753.js";import{c as u,b as x,a as $}from"./index.esm-62d6b2f7.js";import{o as z}from"./yup-92678dde.js";import{u as B}from"./index.esm-c494934a.js";import"./componentStyles-7753bbb9.js";import{F as I}from"./FormInput-74e2c4d2.js";/* empty css                   */import"./ScrollableList-1962b023.js";import{S as k}from"./SelectComponent-e431868e.js";import{D as N,a as T}from"./DialogContent-89e21f2e.js";import{D as U}from"./DialogTitle-fe69da5c.js";import{D as E}from"./DialogContentText-6688bd59.js";import{D as K}from"./DialogActions-e754942c.js";import{L as y}from"./LoadingButton-3975ddf9.js";const re=({modal:s,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(()=>{s?o({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}):o()},[s,e]);const{control:c,handleSubmit:b,reset:o}=B({resolver:z(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({})),o()}};i(L(p))}else{const p={obj:{name:t.name,type:t.type.value},pageParams:m,clearDataFn:()=>{a(),i(d({})),o()}};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:s,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(A,{onClick:a,children:r.jsx(q,{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(k,{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(I,{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};
