import{b as $,r as d,a as q,h as B,vt as L,j as e,I as P,ec as T,K as t,vu as U,vv as z,vw as x}from"./index-60a3c753.js";import{c as K,b as N}from"./index.esm-62d6b2f7.js";import{o as R}from"./yup-92678dde.js";import{u as V}from"./index.esm-c494934a.js";import"./componentStyles-7753bbb9.js";import{F as X}from"./FormInput-74e2c4d2.js";/* empty css                   */import"./ScrollableList-1962b023.js";import{D as y,a as j}from"./DialogContent-89e21f2e.js";import{D as g}from"./DialogTitle-fe69da5c.js";import{D as C}from"./DialogContentText-6688bd59.js";import{D as f}from"./DialogActions-e754942c.js";const ae=({modal:i,closeModal:c,mastersName:b,edit_Id:r,mastersValue:Z})=>{const n=$(),[v,l]=d.useState(!1),{category:{selectedData:o,pageParams:u},system:{userAccessList:G}}=q(s=>({system:B(s),category:L(s)})),S=K().shape({name:N().required("Please enter your category name").trim().matches(/^[a-zA-Z0-9 ]*$/,"category name should not contain special characters")});d.useEffect(()=>{i?a({name:(o==null?void 0:o.name)||""}):a()},[i,o]);const{control:w,handleSubmit:A,reset:a}=V({resolver:R(S),values:{name:o!=null&&o.name?o==null?void 0:o.name:""}}),m=()=>{l(!0)},D=()=>{l(!1),c(),a()},h=()=>{l(!1)},F=s=>{if(r==null||r==""){const p={obj:{name:s.name},pageParams:u,clearDataFn:()=>{c(),n(x({})),a()},navigate:E=>{}};n(U(p))}else{const p={obj:{id:r,name:s.name},pageParams:u,clearDataFn:()=>{c(),a(),n(x({}))},navigate:E=>{}};n(z(p))}};return e.jsxs(e.Fragment,{children:[e.jsxs(y,{open:i,onClose:m,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[e.jsxs(g,{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==0?"Add ":"Update ",b,e.jsx(P,{onClick:m,children:e.jsx(T,{color:"white"})})]}),e.jsx(j,{sx:{px:"24px",pt:"12px !important",pb:0},children:e.jsx(C,{id:"alert-dialog-description",sx:{width:500},children:e.jsxs("form",{style:{width:"100%"},onSubmit:A(F),children:[e.jsx(X,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter Category here...",control:w}),e.jsxs(f,{sx:{p:2},children:[e.jsx(t,{onClick:m,variant:"outlined",color:"secondary",children:"Cancel"}),r==null||r==""?e.jsx(t,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Submit"}):e.jsx(t,{variant:"contained",type:"submit",color:"primary",autoFocus:!0,children:"Update"})]})]})})})]}),e.jsxs(y,{open:v,onClose:h,children:[e.jsx(g,{children:"Confirm Close"}),e.jsx(j,{children:e.jsx(C,{children:"⚠️ Are you sure you want to close? Any unsaved changes will be lost."})}),e.jsxs(f,{children:[e.jsx(t,{onClick:h,color:"primary",children:"Cancel"}),e.jsx(t,{onClick:D,color:"error",variant:"contained",children:"Close"})]})]})]})};export{ae as A};
