import { MapLayout } from './components/map/MapLayout';
import { PlayerDashboardFullPage } from './components/PlayerDashboardFullPage';
import { useLiveData } from './hooks/useLiveData';
import './styles/map-layout.css';

/**
 * Single SPA entry. Branches on `?view=` query param:
 *   /?view=dashboard  → fullscreen PlayerDashboardFullPage (new-tab target)
 *   /                 → default map + sidebar layout
 *
 * We don't pull in react-router for one extra view — when a third view
 * appears, swap this for proper routing.
 */
export default function App() {
  const view = new URLSearchParams(window.location.search).get('view');
  if (view === 'dashboard') {
    return <PlayerDashboardFullPage />;
  }
  // Default: full app with map + sidebar.
  return <DefaultApp />;
}

/** Default map-and-sidebar layout. Split out so the dashboard tab doesn't
 *  spin up useLiveData twice for the same render. */
function DefaultApp() {
  const data = useLiveData();
  return <MapLayout data={data} />;
}
