import React from "react";
import ReactDOM from "react-dom/client";
import { App } from "./App";
import { ViewMode } from "./routes/ViewMode";

const renderResistants = (defaultViewMode: ViewMode) => {
  ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
    <React.StrictMode>
      <App defaultViewMode={defaultViewMode} />
    </React.StrictMode>
  );
};

const render = () => {
  const defaultViewMode: ViewMode = location.href.includes("resistants")
    ? "photos"
    : "map";

  renderResistants(defaultViewMode);
};

if ("Squarespace" in window) {
  // @ts-ignore
  window.Squarespace.onInitialize(Y, render);
} else {
  render();
}
