/** React bootstrap: mounts the app inside the DI provider. */

import React from "react";
import ReactDOM from "react-dom/client";

import { App } from "./App";
import { ViewWindow, parseViewWindowParams } from "./ViewWindow";
import { DIProvider } from "./di";
import "@/shared/styles/theme.css";

const root = document.getElementById("root");
if (!root) {
  throw new Error("missing #root element");
}

// #23/#47: a detached view window loads the SPA with `?panel=` (panel-only, no
// project id). When the param is present and valid, render only that view — it
// follows the main window's focused project; otherwise the full app.
const viewParams = parseViewWindowParams(window.location.search);

ReactDOM.createRoot(root).render(
  <React.StrictMode>
    <DIProvider>
      {viewParams ? (
        <ViewWindow panel={viewParams.panel} />
      ) : (
        <App />
      )}
    </DIProvider>
  </React.StrictMode>,
);
