"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Phase4 = Phase4;
require("core-js/modules/web.dom-collections.iterator.js");
var _react = require("react");
var _flagsTarget = require("../assets/flags-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 Phase4(_ref) {
  let {
    nextPhase
  } = _ref;
  const [flagTargetState, setFlagsTargetState] = (0, _react.useState)("visible");
  const onCogButtonClick = (0, _react.useCallback)(() => {
    // setFlagsTargetState("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(() => {
      setFlagsTargetState("animation");
    }, 2500);
  }, []);
  const onFlagsTargetAnimationEnded = (0, _react.useCallback)(() => {
    setFlagsTargetState("hidden");
    nextPhase();
  }, []);
  const cogIconClassNames = [_stylesModule.default.bareBlockIconFullScreen, flagTargetState === "animation" ? _stylesModule.default.fadeOutAnimation : "", flagTargetState === "hidden" ? _stylesModule.default.hide : "", flagTargetState === "visible" ? _stylesModule.default.show : ""].join(" ");
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: _stylesModule.default.singleColumnContainer,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_flagsTarget.ReactComponent, {
      className: cogIconClassNames,
      onClick: onCogButtonClick,
      onAnimationEnd: onFlagsTargetAnimationEnded
    })
  });
}