import{b as q,r as d,a as $,h as B,vo as L,j as e,I as P,ec as T,K as t,vp as U,vq as z,vr as x}from"./index-76d4793e.js";import{c as K,b as N}from"./index.esm-ad8a7c9f.js";import{o as R}from"./yup-688ec4f6.js";import{u as V}from"./index.esm-3adfd9f7.js";import"./componentStyles-0803b39e.js";import{F as X}from"./FormInput-8f40ded1.js";/* empty css                   */import"./ScrollableList-4dae3697.js";import{D as y,a as j}from"./DialogContent-7bd8dd8f.js";import{D as g}from"./DialogTitle-71dd5b3a.js";import{D as C}from"./DialogContentText-7642f81f.js";import{D as f}from"./DialogActions-5a5e1db9.js";const ae=({modal:i,closeModal:c,mastersName:b,edit_Id:r,mastersValue:Z})=>{const n=q(),[v,l]=d.useState(!1),{category:{selectedData:o,pageParams:h},system:{userAccessList:G}}=$(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:A,handleSubmit:w,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()},u=()=>{l(!1)},F=s=>{if(r==null||r==""){const p={obj:{name:s.name},pageParams:h,clearDataFn:()=>{c(),n(x({})),a()},navigate:E=>{}};n(U(p))}else{const p={obj:{id:r,name:s.name},pageParams:h,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:w(F),children:[e.jsx(X,{name:"name",label:"Name",required:!0,type:"text",placeholder:"Enter Category here...",control:A}),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:u,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:u,color:"primary",children:"Cancel"}),e.jsx(t,{onClick:D,color:"error",variant:"contained",children:"Close"})]})]})]})};export{ae as A};
