"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _styledComponents = require("styled-components");

var _styledComponents2 = _interopRequireDefault(_styledComponents);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var ButtonContainer = _styledComponents2.default.button.withConfig({
  displayName: "MenuButton__ButtonContainer"
})(["appearance:none;background:none;border:none;display:block;float:right;height:1rem;padding:0;position:relative;transform:rotate(0deg);transition:transform 500ms ease;width:1.5rem;outline:none;> span{background-color:", ";border-radius:var(--smBorderRadius);display:block;height:2px;position:relative;right:0;top:0;left:0;}> span::before,> span::after{background-color:", ";border-radius:var(--smBorderRadius);content:\"\";display:block;height:2px;left:0;position:absolute;width:100%;transition-duration:200ms,250ms;transition-delay:250ms,0s;}> span::before{top:-6px;transition-property:top,transform;}> span::after{bottom:-6px;transition-property:bottom,transform;}&.is-active{transform:rotate(180deg);transition-delay:100ms;}&.is-active > span{background:none;}&.is-active > span::before,&.is-active > span::after{transition-delay:0s,250ms;background-color:white;}&.is-active > span::before{top:0;transform:rotate(45deg);}&.is-active > span::after{bottom:0;transform:rotate(-45deg);}"], function (props) {
  return props.color ? props.color : "white";
}, function (props) {
  return props.color ? props.color : "white";
});

var MenuButton = function (_PureComponent) {
  _inherits(MenuButton, _PureComponent);

  function MenuButton() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, MenuButton);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = MenuButton.__proto__ || Object.getPrototypeOf(MenuButton)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
      active: false
    }, _this.handleClick = function () {
      var nextActive = !_this.state.active;
      _this.setState({ active: nextActive });
      if (_this.props.callback) {
        _this.props.callback(nextActive);
      }
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(MenuButton, [{
    key: "render",
    value: function render() {
      var classes = this.state.active ? "is-active" : "";
      return _react2.default.createElement(
        ButtonContainer,
        {
          color: this.props.color,
          className: classes,
          onClick: this.handleClick },
        _react2.default.createElement("span", null)
      );
    }
  }], [{
    key: "getDerivedStateFromProps",
    value: function getDerivedStateFromProps(nextProps, prevState) {
      var active = prevState.active;
      if (nextProps.hasOwnProperty("active")) {
        active = nextProps.active;
      }
      return { active: active };
    }
  }]);

  return MenuButton;
}(_react.PureComponent);

exports.default = MenuButton;