"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Phase0 = Phase0;
require("core-js/modules/web.dom-collections.iterator.js");
var _react = require("react");
var _greenTick = require("../assets/green-tick.svg");
var _stylesModule = _interopRequireDefault(require("./styles.module.css"));
var _CogManager = require("../utils/CogManager");
var _ClickCogAnimation = _interopRequireDefault(require("./ClickCogAnimation"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function Phase0(_ref) {
  let {
    nextPhase
  } = _ref;
  const [tickIconState, setTickIconState] = (0, _react.useState)("hidden");
  const [cogIconState, setCogIconState] = (0, _react.useState)("visible");
  const onCogButtonClick = (0, _react.useCallback)(() => {
    setCogIconState("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);
      };
    }
  }, []);
  const onCogIconAnimationEnd = (0, _react.useCallback)(() => {
    setCogIconState("hidden");
    setTickIconState("animation");
  }, []);
  const onTickIconAnimationEnd = (0, _react.useCallback)(() => {
    nextPhase();
  }, []);
  const cogIconClassNames = [_stylesModule.default.bareBlockIconFullScreen, cogIconState === "animation" ? _stylesModule.default.fadeOutAnimation : "", cogIconState === "hidden" ? _stylesModule.default.hide : "", cogIconState === "visible" ? _stylesModule.default.show : ""].join(" ");
  const tickIconClassNames = [_stylesModule.default.tickIconFullScreen, tickIconState === "animation" ? _stylesModule.default.fadeInAnimation : "", tickIconState === "hidden" ? _stylesModule.default.hide : "", tickIconState === "visible" ? _stylesModule.default.show : ""].join(" ");
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: _stylesModule.default.singleColumnContainer,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      onAnimationEnd: onCogIconAnimationEnd,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ClickCogAnimation.default, {
        className: cogIconClassNames
      })
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_greenTick.ReactComponent, {
      className: tickIconClassNames,
      onAnimationEnd: onTickIconAnimationEnd
    })]
  });
}