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-def636a4.js";import{c as u,b as x,a as $}from"./index.esm-eec4f448.js";import{o as z}from"./yup-c8535458.js";import{u as B}from"./index.esm-7d9d1491.js";import"./componentStyles-41382c67.js";import{F as I}from"./FormInput-8d872744.js";/* empty css                   */import"./ScrollableList-a550bc32.js";import{S as k}from"./SelectComponent-cea9b89b.js";import{D as N,a as T}from"./DialogContent-0cb684b3.js";import{D as U}from"./DialogTitle-e2e75924.js";import{D as E}from"./DialogContentText-b2259947.js";import{D as K}from"./DialogActions-c4045764.js";import{L as y}from"./LoadingButton-621a0e8f.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};
