/* global React, ReactDOM */ const { useState, useEffect } = React; const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{ "role": "admin", "font": "inter", "viewport": "desktop" }/*EDITMODE-END*/; function App() { const [t, setTweak] = window.useTweaks(TWEAK_DEFAULTS); const [activeId, setActiveId] = useState('inicio'); const [detalleId, setDetalleId] = useState(null); // Slide-overs const [nuevaOpen, setNuevaOpen] = useState(false); const [cargarOpen, setCargarOpen] = useState(false); const [cargarFor, setCargarFor] = useState(null); const [nuevaInstOpen, setNuevaInstOpen] = useState(false); const [nuevoUserOpen, setNuevoUserOpen] = useState(false); // Reset to home when role changes useEffect(() => { setActiveId('inicio'); setDetalleId(null); setNuevaOpen(false); setCargarOpen(false); }, [t.role]); useEffect(() => { document.documentElement.dataset.font = t.font; }, [t.font]); const user = window.ROLES[t.role] || window.ROLES.admin; const modules = window.modulesForRole(t.role); const activeModule = modules.find(m => m.id === activeId) || modules[0]; // ---- Routers const goNav = (id) => { // Detail closes when changing nav setDetalleId(null); // Special: "Nueva recomendación" nav opens the slide-over and stays on Compromisos if (id === 'nueva_recomendacion') { setActiveId('compromisos'); setNuevaOpen(true); return; } // Special: "Cargar Avance" nav opens the panel and stays on Mis Compromisos if (id === 'cargar_avance') { setActiveId('mis_compromisos'); setCargarFor(null); // auto-pick a pending or returned one inside the panel setCargarOpen(true); return; } setActiveId(id); }; const openDetalle = (id) => setDetalleId(id); const closeDetalle = () => setDetalleId(null); const openCargar = (id) => { setCargarFor(id); setCargarOpen(true); }; // Mobile mode if (t.viewport === 'mobile') { return ( <> {}} /> ); } // What to render in main area let screen; if (detalleId) { screen = ( ); } else if (activeId === 'inicio') { screen = ; } else if (activeId === 'tablero') { screen = ; } else if (activeId === 'compromisos') { screen = ( setNuevaOpen(true)} /> ); } else if (activeId === 'mis_compromisos') { screen = ( ); } else if (activeId === 'alertas') { screen = ( ); } else if (activeId === 'mensajeria') { screen = ( ); } else if (activeId === 'reportes') { screen = ; } else if (activeId === 'reportes_aprobados') { screen = ; } else if (activeId === 'usuarios') { screen = setNuevoUserOpen(true)} />; } else if (activeId === 'instituciones') { screen = setNuevaInstOpen(true)} />; } else if (activeId === 'portal') { screen = ; } else { screen = setActiveId('inicio')} />; } // Breadcrumb / topbar title let topbarTitle = activeModule.title; if (detalleId) topbarTitle = `Detalle · ${detalleId}`; return ( <>
{screen}
{/* Slide-overs */} setNuevaOpen(false)} onSave={() => { /* mock */ }} /> setCargarOpen(false)} onSubmit={() => { /* mock */ }} /> setNuevaInstOpen(false)} onSave={() => { /* mock */ }} /> setNuevoUserOpen(false)} onSave={() => { /* mock */ }} /> ); } // ---------------- Tweaks ---------------- function Tweaks({ t, setTweak }) { const { TweaksPanel, TweakSection, TweakRadio, TweakSelect } = window; return ( setTweak('role', v)} options={[ { value: 'superadmin', label: 'Súper Administrador (CGR)' }, { value: 'admin', label: 'Administrador (CGR · Análisis)' }, { value: 'institucion', label: 'Institución Reportante (UTA)' }, { value: 'cancilleria', label: 'Cancillería (solo lectura)' }, ]} /> setTweak('font', v)} options={[ { value: 'inter', label: 'Inter' }, { value: 'jakarta', label: 'Jakarta' }, { value: 'ibm', label: 'IBM Plex' }, ]} /> setTweak('viewport', v)} options={[ { value: 'desktop', label: 'Desktop' }, { value: 'mobile', label: 'Mobile' }, ]} /> ); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render();