import{b as $,r as h,a as q,g as B,vt as L,j as e,I as P,ef as T,J as t,vu as U,vv as z,vw as x}from"./index-d2b25495.js";import{c as J,b as N}from"./index.esm-3043d6d4.js";import{o as R}from"./yup-267e586f.js";import{u as V}from"./index.esm-ce3c2c20.js";import"./componentStyles-0e851d91.js";import{F as X}from"./FormInput-d202e905.js";/* empty css                   */import"./ScrollableList-fc1de312.js";import{D as y,a as g}from"./DialogContent-cded694d.js";import{D as j}from"./DialogTitle-a145b392.js";import{D as C}from"./DialogContentText-43575e44.js";import{D as f}from"./DialogActions-7c802cc8.js";const ae=({modal:i,closeModal:c,mastersName:b,edit_Id:r,mastersValue:Z})=>{const n=$(),[v,l]=h.useState(!1),{category:{selectedData:o,pageParams:u},system:{userAccessList:G}}=q(s=>({system:B(s),category:L(s)})),S=J().shape({name:N().required("Please enter your category name").trim().matches(/^[a-zA-Z0-9 ]*$/,"category name should not contain special characters")});h.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()},d=()=>{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(j,{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(g,{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:d,children:[e.jsx(j,{children:"Confirm Close"}),e.jsx(g,{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:d,color:"primary",children:"Cancel"}),e.jsx(t,{onClick:D,color:"error",variant:"contained",children:"Close"})]})]})]})};export{ae as A};
