import{b as f,a as v,vx as S,r as F,j as r,I as A,ef as q,P as C,J as P,vy as w,vz as L,vA as d}from"./index-d2b25495.js";import{c as u,b as x,a as $}from"./index.esm-3043d6d4.js";import{o as z}from"./yup-267e586f.js";import{u as B}from"./index.esm-ce3c2c20.js";import"./componentStyles-0e851d91.js";import{F as I}from"./FormInput-d202e905.js";/* empty css                   */import"./ScrollableList-fc1de312.js";import{S as k}from"./SelectComponent-d286bfef.js";import{D as N,a as T}from"./DialogContent-cded694d.js";import{D as U}from"./DialogTitle-a145b392.js";import{D as E}from"./DialogContentText-43575e44.js";import{D as J}from"./DialogActions-7c802cc8.js";import{L as y}from"./LoadingButton-c8e88148.js";const re=({modal:s,setModalOpen:R,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(w(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(J,{sx:{p:2},children:[r.jsx(P,{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};
