/**
 * @fileoverview React component for MoleMash.jsx
 * 
 * @module games.mole-mash.MoleMash
 */


import React, { useEffect, useMemo } from "react";
import PropTypes from "prop-types";
import GameBase from "../../../components/game/GameBase";
import GameEditor from "../../../components/game/GameEditor";
import BlocklyEditor from "../../../components/game/editors/BlocklyEditor";
import { createGame } from "./game";
import { gameConfig } from "./config/config";
import { registerBlocks, generateDynamicToolbox } from "./blocks/blocks";
import {
  GameStateProvider,
  useGameState,
} from "../../../contexts/GameStateContext";
import { useMoleMashTour } from "./hooks/useMoleMashTour";
import { debugSolutions } from "./config/debugSolutions";
import "shepherd.js/dist/css/shepherd.css";
import "../../../styles/shepherd-theme.css";

/**
 * Componente que monta o conteúdo do jogo Toupeira.
 * Registra blocos e provê o editor Blockly.
 * @returns {JSX.Element} Elemento do jogo com editor Blockly.
 */
/**
 * Componente que monta o conteúdo do jogo Toupeira.
 * Registra blocos e provê o editor Blockly.
 * @returns {JSX.Element} Elemento do jogo com editor Blockly.
 */
function MoleMashContent() {
  const { startTour } = useMoleMashTour();
  const { setFailureMessage, isDebugMode } = useGameState();

  useEffect(() => {
    registerBlocks();
  }, []);

  const toolboxGenerator = useMemo(() => {


    return (allowedBlocks) => generateDynamicToolbox(allowedBlocks);
  }, []);

  return (
    <GameBase
      gameFactory={createGame}
      gameConfig={gameConfig}
      onHelpClick={startTour}
      helpHandler={startTour}
      customFailureHandler={setFailureMessage}
      failureHandler={setFailureMessage}
    >
      <GameEditor>
        <BlocklyEditor
          toolboxGenerator={toolboxGenerator}
          debugSolutions={isDebugMode ? debugSolutions : null}
        />
      </GameEditor>
    </GameBase>
  );
}

/**
 * Componente wrapper que provê `GameStateProvider` para o jogo Toupeira.
 * @returns {JSX.Element} Componente principal do jogo.
 */
/**
 * Componente wrapper que provê `GameStateProvider` para o jogo Toupeira.
 * @returns {JSX.Element} Componente principal do jogo.
 */
export default function MoleMashGame() {
  return (
    <GameStateProvider gameConfig={gameConfig}>
      <MoleMashContent />
    </GameStateProvider>
  );
}

MoleMashContent.propTypes = {};
MoleMashGame.propTypes = {};
