import { FROZEN, RACE } from "../../../domain/ruleSets";
import { useGameConfig } from "../../../hooks/useGameInfo";
import usePreventNavigation from "../../../hooks/usePreventNavigation";
import Loading from "../../util/Loading";
import styles from "./GamePanel.module.css";
import GuessPane from "./GuessPane";
import PositionedStreetView from "./PositionedStreetView";
import RaceMode from "./RaceMode";
import useIsFinished from "./useIsFinished";

const GamePanel = () => {
  // warn the user if they navigate away
  usePreventNavigation();
  const { ruleSet } = useGameConfig();
  const finished = useIsFinished();

  return finished ? (
    <Loading />
  ) : (
    <div className={styles.page}>
      {ruleSet === RACE && <RaceMode rate={1000} cutoffTime={10} />}
      <div className={styles.streetview}>
        <PositionedStreetView />
        {ruleSet === FROZEN && <div className={styles.freeze} />}
      </div>
      <GuessPane />
    </div>
  );
};

export default GamePanel;
