import { createBrowserRouter, Navigate } from 'react-router-dom';
import { useParams } from 'react-router-dom';

import DualModalComponent from './layouts/DualModal';

import CouncilAI from './components/CouncilAI/CouncilAI';
import FuseMindHome from './components/FuseMind/FuseMindHome';
import CanvasEndpoints from './components/canvas-api/CanvasEndpoints';

const FuseMindHomeWrapper = () => {
  const { systemId } = useParams();
  return systemId === 'fusemind' ? <FuseMindHome /> : null;
};

const router = createBrowserRouter([
  {
    path: '/',
    element: <Navigate to='dashboard' replace />,
  },
  {
    path: 'dashboard',
    element: <DualModalComponent />,
    children: [
      {
        path: ':systemId',
        children: [
          {
            path: 'chat',
            element: <CouncilAI />,
          },
          {
            path: 'home',
            element: <FuseMindHomeWrapper />,
          },
          {
            path: 'endpoints',
            element: <CanvasEndpoints />,
          },
          {
            path: 'canvas-endpoints',
            element: <CanvasEndpoints />,
          },
        ],
      },
    ],
  },
  {
    path: '*',
    element: <p>Error: Page not found here?</p>,
  },
]);

export default router;
