1import{r as o,j as e,D as R,p as B,I as K,d as D,c as k,G as m,B as L,T,_ as Q,q as U}from"./index-MQgKJfMF.js";import{B as V}from"./BackdropLoader-DiM0jzIV.js";import{C as X}from"./CustomTable-4cP-YmCp.js";import{C as Y}from"./Close-BmU2v8OV.js";import{T as p}from"./TextField-Cs0jE3AU.js";import{M as C}from"./LastPage-BZazBV8o.js";import{m as N}from"./modalPageService-DufdOpAz.js";import{m as Z}from"./menuService-B1-Y8619.js";import{s as $}from"./subMenuService-B-47Hghx.js";import"./TableRow-ZH9PIRjT.js";import"./TableCell-D2s0VBgg.js";const A={menuId:"",subMenuId:"",pageLabel:"",pageName:"",routePath:"",sequenceNo:"",icon:"",active:!0};function x({children:t,required:h=!1}){return e.jsxs(T,{variant:"caption",sx:{display:"block",mb:.75,fontWeight:500,color:"text.secondary",fontSize:"0.95rem"},children:[t,h&&e.jsx(k,{component:"span",sx:{color:"error.main",ml:.25},children:"*"})]})}function ee({open:t,onClose:h,onSave:y,modelData:l,menus:P=[],subMenus:I=[],loading:b=!1}){const[s,g]=o.useState(A);o.useEffect(()=>{g(t?{menuId:l?.menuId??"",subMenuId:l?.subMenuId??"",pageLabel:l?.pageLabel??l?.modalPageLabel??"",pageName:l?.pageName??l?.modalPageName??"",routePath:l?.routePath??"",sequenceNo:l?.sequenceNo??"",icon:l?.icon??"",active:l?.active??!0}:A)},[t,l]);const q=Array.isArray(P)?P:[],f=Array.isArray(I)?I:[],M=o.useMemo(()=>s.menuId?f.filter(n=>Number(n.menuId)===Number(s.menuId)):[],[s.menuId,f]),i=n=>{const{name:u,value:c}=n.target;if(u==="menuId"){g(v=>({...v,menuId:c,subMenuId:""}));return}g(v=>({...v,[u]:u==="sequenceNo"?c.replace(/[^0-9]/g,""):c}))},F=()=>{y?.({subMenuId:Number(s.subMenuId),pageName:s.pageName,pageLabel:s.pageLabel,routePath:s.routePath,sequenceNo:Number(s.sequenceNo),icon:s.icon,active:s.active})},j=!!l?.id,d={"& .MuiOutlinedInput-root":{borderRadius:"4px",backgroundColor:"#fff",minHeight:42}};return e.jsxs(R,{open:t,onClose:b?void 0:h,fullWidth:!0,maxWidth:"md",PaperProps:{sx:{borderRadius:1,overflow:"hidden"}},children:[e.jsxs(B,{sx:{px:2.5,py:2,fontWeight:500,fontSize:"2rem",borderBottom:"1px solid #e0e0e0",position:"relative"},children:[j?"Edit Modal Page":"New Modal Page",e.jsx(K,{onClick:h,disabled:b,sx:{position:"absolute",right:12,top:12,color:"#ff4d4f"},children:e.jsx(Y,{})})]}),e.jsx(D,{sx:{p:3},children:e.jsxs(k,{sx:{border:"1px solid #d9d9d9",borderRadius:1,p:2.5},children:[e.jsxs(m,{container:!0,spacing:2.5,children:[e.jsxs(m,{size:12,children:[e.jsx(x,{required:!0,children:"Menu"}),e.jsxs(p,{select:!0,fullWidth:!0,size:"small",name:"menuId",value:s.menuId,onChange:i,sx:d,children:[e.jsx(C,{value:"",disabled:!0,children:"Select Menu"}),q.map(n=>e.jsx(C,{value:n.id,children:n.menuLabel},n.id))]})]}),e.jsxs(m,{size:12,children:[e.jsx(x,{required:!0,children:"Sub Menu"}),e.jsxs(p,{select:!0,fullWidth:!0,size:"small",name:"subMenuId",value:s.subMenuId,onChange:i,sx:d,children:[e.jsx(C,{value:"",disabled:!0,children:"Select Sub Menu"}),M.map(n=>e.jsx(C,{value:n.id,children:n.subMenuLabel},n.id))]})]}),e.jsxs(m,{size:12,children:[e.jsx(x,{required:!0,children:"Modal Page Label"}),e.jsx(p,{fullWidth:!0,size:"small",name:"pageLabel",value:s.pageLabel,onChange:i,placeholder:"Enter Modal Page Label",sx:d})]}),e.jsxs(m,{size:12,children:[e.jsx(x,{required:!0,children:"Modal Page Name"}),e.jsx(p,{fullWidth:!0,size:"small",name:"pageName",value:s.pageName,onChange:i,placeholder:"Enter Modal Page Name",sx:d})]}),e.jsxs(m,{size:12,children:[e.jsx(x,{children:"Route Path"}),e.jsx(p,{fullWidth:!0,size:"small",name:"routePath",value:s.routePath,onChange:i,placeholder:"Enter Route Path",sx:d})]}),e.jsxs(m,{size:12,children:[e.jsx(x,{children:"Sequence No"}),e.jsx(p,{fullWidth:!0,size:"small",name:"sequenceNo",value:s.sequenceNo,onChange:i,placeholder:"Enter Sequence No",sx:d})]}),e.jsxs(m,{size:12,children:[e.jsx(x,{children:"Icon"}),e.jsx(p,{fullWidth:!0,size:"small",name:"icon",value:s.icon,onChange:i,placeholder:"Enter Icon",sx:d})]})]}),e.jsxs(k,{sx:{display:"flex",justifyContent:"flex-end",gap:2,mt:2.5},children:[e.jsx(L,{onClick:F,disabled:b,variant:"contained",sx:{minWidth:64},children:"Save"}),e.jsx(L,{onClick:h,disabled:b,variant:"outlined",color:"inherit",sx:{minWidth:76,borderColor:"#bdbdbd",color:"text.secondary"},children:"Cancel"})]})]})})]})}const ae={menuId:"",subMenuId:"",pageLabel:"",pageName:"",routePath:"",sequenceNo:"",icon:"",active:!0};function he(){const{enqueueSnackbar:t}=Q(),[h,y]=o.useState([]),[l,P]=o.useState([]),[I,b]=o.useState([]),[s,g]=o.useState(!1),[q,f]=o.useState(!1),[M,i]=o.useState(null),[F,j]=o.useState(!1),[d,n]=o.useState(null),[u,c]=o.useState(!1);o.useEffect(()=>
1{v()},[]);const v=async()=>{g(!0);try{const[a,r,S]=await Promise.all([N.getModalPages(),Z.getMenus(),$.getSubMenus()]);a.success?y(a.data||[]):t(a.message||"Failed to load modal pages",{variant:"error"}),r.success?P(r.data||[]):t(r.message||"Failed to load menus",{variant:"error"}),S.success?b(S.data||[]):t(S.message||"Failed to load sub menus",{variant:"error"})}catch(a){t(a.message||"Failed to load data",{variant:"error"})}finally{g(!1)}},z=async()=>{try{const a=await N.getModalPages();a.success?y(a.data||[]):t(a.message||"Failed to load modal pages",{variant:"error"})}catch(a){t(a.message||"Failed to load modal pages",{variant:"error"})}},w=[{label:"Sl. No.",key:"slNo",render:(a,r,S)=>S+1},{label:"Menu",key:"menuLabel"},{label:"Sub Menu",key:"subMenuLabel"},{label:"Modal Page Label",key:"pageLabel"},{label:"Modal Page Name",key:"pageName"},{label:"Route Path",key:"routePath"},{label:"Sequence No",key:"sequenceNo"}],O=()=>{i(null),f(!0)},_=a=>{i({...a,menuId:a.menuId,subMenuId:a.subMenuId,pageLabel:a.pageLabel,pageName:a.pageName,routePath:a.routePath,sequenceNo:a.sequenceNo,icon:a.icon,active:a.active}),f(!0)},W=()=>{f(!1),i(null)},G=async a=>{c(!0);try{let r;M?r=await N.updateModalPage(M.id,a):r=await N.createModalPage(a),r.success?(t(r.message||"Modal page saved successfully",{variant:"success"}),W(),z()):t(r.message||"Failed to save modal page",{variant:"error"})}catch(r){t(r.message||"Failed to save modal page",{variant:"error"})}finally{c(!1)}},H=a=>{n(a),j(!0)},J=async()=>{if(d){c(!0);try{const a=await N.deleteModalPage(d.id);a.success?(t(a.message||"Modal page deleted successfully",{variant:"success"}),j(!1),n(null),z()):t(a.message||"Failed to delete modal page",{variant:"error"})}catch(a){t(a.message||"Failed to delete modal page",{variant:"error"})}finally{c(!1)}}},E=()=>{j(!1),n(null)};return e.jsxs(e.Fragment,{children:[e.jsx(V,{open:s||u}),e.jsx(X,{title:"Modal Page",rows:h,headers:w,onAdd:O,onEdit:_,onDelete:H,addButtonLabel:"Add Modal",isActionsFieldShow:!0,showSearch:!0}),e.jsx(ee,{open:q,onClose:W,onSave:G,modelData:M||ae,menus:l,subMenus:I,loading:u}),e.jsxs(R,{open:F,onClose:u?void 0:E,fullWidth:!0,maxWidth:"xs",children:[e.jsx(B,{children:"Delete Modal Page"}),e.jsx(D,{children:e.jsxs(T,{variant:"body1",children:['Are you sure you want to delete "',d?.pageLabel||"",'"? This action cannot be undone.']})}),e.jsxs(U,{sx:{p:2},children:[e.jsx(L,{onClick:E,color:"secondary",disabled:u,children:"Cancel"}),e.jsx(L,{onClick:J,color:"error",variant:"contained",disabled:u,children:"Delete"})]})]})]})}export{he as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.