"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Phase5 = Phase5;
require("core-js/modules/web.dom-collections.iterator.js");
var _react = require("react");
var _starTarget = require("../assets/star-target.svg");
var _stylesModule = _interopRequireDefault(require("./styles.module.css"));
var _CogManager = require("../utils/CogManager");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function Phase5(_ref) {
  let {
    nextPhase
  } = _ref;
  const [starTargetState, setStarTargetState] = (0, _react.useState)("visible");
  const onCogButtonClick = (0, _react.useCallback)(() => {
    // setStarTargetState("animation");
  }, []);
  (0, _react.useEffect)(() => {
    const connectedCog = (0, _CogManager.getConnectedCog)();
    if (connectedCog) {
      const eventName = connectedCog.publishedDataAnalyser.eventsMap.buttonClick.release;
      connectedCog.publishedDataAnalyser.addListener(eventName, onCogButtonClick);
      return () => {
        connectedCog.publishedDataAnalyser.removeListener(eventName, onCogButtonClick);
      };
    }
  }, []);
  (0, _react.useEffect)(() => {
    setTimeout(() => {
      setStarTargetState("animation");
    }, 1500);
  }, []);
  const onStarTargetAnimationEnded = (0, _react.useCallback)(() => {
    setStarTargetState("hidden");
    nextPhase();
  }, []);
  const cogIconClassNames = [_stylesModule.default.bareBlockIconFullScreen, starTargetState === "animation" ? _stylesModule.default.fadeOutAnimation : "", starTargetState === "hidden" ? _stylesModule.default.hide : "", starTargetState === "visible" ? _stylesModule.default.show : ""].join(" ");
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: _stylesModule.default.singleColumnContainer,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_starTarget.ReactComponent, {
      className: cogIconClassNames,
      onClick: onCogButtonClick,
      onAnimationEnd: onStarTargetAnimationEnded
    })
  });
}