import { useEffect, useState } from "preact/hooks";
import App from "@/App";
import SearchRoutePage from "@/pages/search-route-page";

export function RootRouter() {
  const [path, setPath] = useState(window.location.pathname);

  useEffect(() => {
    const onPopState = () => setPath(window.location.pathname);
    window.addEventListener("popstate", onPopState);
    return () => window.removeEventListener("popstate", onPopState);
  }, []);

  if (path === "/search") {
    return <SearchRoutePage />;
  }
  return <App />;
}
