"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PhaserGame = void 0;
var _react = require("react");
var _main = _interopRequireDefault(require("./main"));
var _EventBus = require("./EventBus");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const PhaserGame = exports.PhaserGame = /*#__PURE__*/(0, _react.forwardRef)(function PhaserGame(_ref, ref) {
  let {
    currentActiveScene
  } = _ref;
  const game = (0, _react.useRef)(null);
  (0, _react.useLayoutEffect)(() => {
    if (game.current === null) {
      game.current = (0, _main.default)("jumping-game-container");
      if (typeof ref === 'function') {
        ref({
          game: game.current,
          scene: null
        });
      } else if (ref) {
        ref.current = {
          game: game.current,
          scene: null
        };
      }
    }
    return () => {
      if (game.current) {
        game.current.destroy(true);
        if (game.current !== null) {
          game.current = null;
        }
      }
    };
  }, [ref]);
  (0, _react.useEffect)(() => {
    _EventBus.EventBus.on('current-scene-ready', scene_instance => {
      if (currentActiveScene && typeof currentActiveScene === 'function') {
        currentActiveScene(scene_instance);
      }
      if (typeof ref === 'function') {
        ref({
          game: game.current,
          scene: scene_instance
        });
      } else if (ref) {
        ref.current = {
          game: game.current,
          scene: scene_instance
        };
      }
    });
    return () => {
      _EventBus.EventBus.removeListener('current-scene-ready');
    };
  }, [currentActiveScene, ref]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    id: "jumping-game-container"
  });
});