"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = BlockSelector;
require("core-js/modules/web.dom-collections.iterator.js");
var _styleModule = _interopRequireDefault(require("./style.module.css"));
var _carousel = _interopRequireDefault(require("./carousel"));
var _wheelFrame = _interopRequireDefault(require("./wheel-frame"));
var _react = require("react");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function BlockSelector(_ref) {
  let {
    gameRef,
    staticBlock,
    staticBlockItems,
    posterItems
  } = _ref;
  const [hasBeenInteracted, setHasBeenInteracted] = (0, _react.useState)(false);
  (0, _react.useEffect)(() => {
    if (!gameRef.current || !gameRef.current.scene) return;
    if (gameRef.current.scene.selectedCogTiltLeftBlock) return;
    if (gameRef.current.scene.selectedCogTiltRightBlock) return;
    const item = posterItems[0];
    switch (staticBlock) {
      case "left":
        gameRef.current.scene.selectedCogTiltLeftBlock = item;
        break;
      case "right":
        gameRef.current.scene.selectedCogTiltRightBlock = item;
        break;
    }
    // gameRef.current.scene.registerCogEvents();
  }, [gameRef.current]);
  const onBlockChange = item => {
    if (!gameRef.current || !gameRef.current.scene) return;
    switch (staticBlock) {
      case "left":
        gameRef.current.scene.selectedCogTiltLeftBlock = item;
        break;
      case "right":
        gameRef.current.scene.selectedCogTiltRightBlock = item;
        break;
    }
    // gameRef.current.scene.registerCogEvents();
  };
  const clickHandler = () => {
    setHasBeenInteracted(true);
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: [_styleModule.default.blockSelector, hasBeenInteracted ? "" : _styleModule.default.uninteracted].join(" "),
    onClick: clickHandler,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: _styleModule.default.carouselContainer,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_wheelFrame.default, {
        Carusel: _carousel.default,
        onFrontPosterChange: item => {},
        posterItems: staticBlockItems,
        isStatic: true
      })
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: _styleModule.default.carouselContainer,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_wheelFrame.default, {
        Carusel: _carousel.default,
        onFrontPosterChange: onBlockChange,
        posterItems: posterItems
      })
    })]
  });
}