"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var _Focusable = require("../../common/Focusable");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _Text = _interopRequireDefault(require("../../Text"));
var _StepMarker = _interopRequireDefault(require("./StepMarker"));
var _constants = require("../constants");
var _StepSt = require("./Step.st.css.js");
var _IconThemeContext = require("../../WixDesignSystemIconThemeProvider/IconThemeContext");
var _excluded = ["type", "styleType", "active", "last", "number", "text", "className", "size"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Stepper/components/Step.jsx";
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var Step = /*#__PURE__*/function (_React$PureComponent) {
  function Step() {
    var _this;
    (0, _classCallCheck2["default"])(this, Step);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, Step, [].concat(args));
    _this.state = {
      isHovered: false,
      // Used to update <Text ellipsis> when CSS transition has ended
      // (otherwise the logic to show/hide tooltip will not be applied)
      transitionSequence: 1
    };
    _this._handleMouseEnter = function () {
      _this.setState({
        isHovered: true
      });
    };
    _this._handleMouseLeave = function () {
      _this.setState({
        isHovered: false
      });
    };
    _this._handleTransitionEnd = function (event) {
      var transitionSequence = _this.state.transitionSequence;
      if (event.propertyName === 'flex-shrink') {
        _this.setState({
          transitionSequence: transitionSequence + 1
        });
      }
    };
    _this._handleClick = function () {
      _this._isClickable() && _this.props.onClick();
    };
    _this._isClickable = function () {
      var _this$props = _this.props,
        onClick = _this$props.onClick,
        type = _this$props.type,
        active = _this$props.active;
      return type !== _constants.StepType.Disabled && !active && !!onClick;
    };
    _this._getFocusProps = function () {
      var _this$props2 = _this.props,
        onClick = _this$props2.onClick,
        focusableOnFocus = _this$props2.focusableOnFocus,
        focusableOnBlur = _this$props2.focusableOnBlur,
        type = _this$props2.type;
      if (onClick && type !== _constants.StepType.Disabled) {
        return {
          onFocus: focusableOnFocus,
          onBlur: focusableOnBlur,
          tabIndex: 0
        };
      }
      return {
        tabIndex: -1
      };
    };
    return _this;
  }
  (0, _inherits2["default"])(Step, _React$PureComponent);
  return (0, _createClass2["default"])(Step, [{
    key: "render",
    value: function render() {
      var _this2 = this;
      var _this$props3 = this.props,
        type = _this$props3.type,
        styleType = _this$props3.styleType,
        active = _this$props3.active,
        last = _this$props3.last,
        number = _this$props3.number,
        text = _this$props3.text,
        className = _this$props3.className,
        size = _this$props3.size,
        otherProps = (0, _objectWithoutProperties2["default"])(_this$props3, _excluded);
      var _this$state = this.state,
        isHovered = _this$state.isHovered,
        transitionSequence = _this$state.transitionSequence;
      var isClickable = this._isClickable();
      return /*#__PURE__*/_react["default"].createElement(_IconThemeContext.IconThemeContext.Consumer, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 78,
          columnNumber: 7
        }
      }, function (_ref) {
        var _themeIcons$Step;
        var _ref$icons = _ref.icons,
          themeIcons = _ref$icons === void 0 ? {} : _ref$icons;
        var icons = {
          ChevronRight: ((_themeIcons$Step = themeIcons.Step) == null ? void 0 : _themeIcons$Step.ChevronRight) || _wixUiIconsCommon.ChevronRight
        };
        return /*#__PURE__*/_react["default"].createElement("button", (0, _extends2["default"])({
          className: (0, _StepSt.st)(_StepSt.classes.root, {
            type: type,
            styleType: styleType,
            size: size,
            selected: active,
            hovered: isHovered,
            clickable: isClickable
          }, className),
          "data-hook": _constants.DataHook.Step,
          "data-type": type,
          "data-size": size,
          "data-active": active,
          onMouseEnter: _this2._handleMouseEnter,
          onMouseLeave: _this2._handleMouseLeave,
          onClick: _this2._handleClick,
          onTransitionEnd: _this2._handleTransitionEnd
        }, _this2._getFocusProps(), {
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 85,
            columnNumber: 13
          }
        }), /*#__PURE__*/_react["default"].createElement("div", {
          className: _StepSt.classes.content,
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 108,
            columnNumber: 15
          }
        }, /*#__PURE__*/_react["default"].createElement(_StepMarker["default"], {
          number: number,
          active: active,
          type: type,
          styleType: styleType,
          hovered: isHovered && isClickable,
          className: _StepSt.classes.marker,
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 109,
            columnNumber: 17
          }
        }), /*#__PURE__*/_react["default"].createElement(_Text["default"], {
          key: transitionSequence,
          ellipsis: true,
          weight: "thin",
          size: size,
          showTooltip: !active,
          dataHook: _constants.DataHook.StepText,
          className: _StepSt.classes.text,
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 117,
            columnNumber: 17
          }
        }, text)), !last && /*#__PURE__*/_react["default"].createElement(icons.ChevronRight, {
          className: _StepSt.classes.arrow,
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 129,
            columnNumber: 25
          }
        }));
      });
    }
  }]);
}(_react["default"].PureComponent);
Step.displayName = 'Step';
Step.defaultProps = {
  type: _constants.StepType.Normal
};
var _default = exports["default"] = (0, _Focusable.withFocusable)(Step);