import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import ImageViewerWindow from "./components/ImageViewerWindow";

// Block all document-level scrolling
document.addEventListener("wheel", (e) => {
  let el = e.target as HTMLElement | null;
  while (el && el !== document.documentElement) {
    const { overflowY } = window.getComputedStyle(el);
    if (overflowY === "scroll" || overflowY === "auto") return;
    el = el.parentElement;
  }
  e.preventDefault();
}, { passive: false });

document.addEventListener("scroll", () => {
  window.scrollTo(0, 0);
}, { passive: true });

const isViewer = new URLSearchParams(window.location.search).get("viewer") === "1";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
  <React.StrictMode>
    {isViewer ? <ImageViewerWindow /> : <App />}
  </React.StrictMode>,
);
