import { IBM_Plex_Mono } from 'next/font/google';
import Sidebar from './components/ui/sidebar-with-submenu.jsx';
import AppChrome from './components/app-chrome.jsx';
import { getInstalledModuleNav } from '../lib/marketplace.js';
import './globals.css';

const ibmPlexMono = IBM_Plex_Mono({
  subsets: ['latin'],
  weight: ['500'],
  variable: '--font-mono-brand',
  display: 'swap',
});

export const metadata = { title: 'madarX OS', description: 'Local-first agent command center for Client Workspace' };

// Sidebar lives in the root layout so it stays mounted across navigations.
// Mounting it inside pages caused a full remount on every route change —
// that was the source of the black-flash and double-click symptoms.
export default function RootLayout({ children }) {
  // Sidebar surfaces from installed marketplace modules (e.g. Mines → /mines).
  // Safe-defaults to [] if the marketplace read fails so chrome always renders.
  let moduleNav = [];
  try { moduleNav = getInstalledModuleNav(); } catch { moduleNav = []; }
  return (
    <html lang="en" className={ibmPlexMono.variable}>
      <body>
        <AppChrome sidebar={<Sidebar moduleNav={moduleNav} />}>{children}</AppChrome>
      </body>
    </html>
  );
}
