"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.ToolMenu = exports.MiniButton = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _classnames = _interopRequireDefault(require("classnames"));

var _renderUi = require("../render-ui");

var _styles = require("@material-ui/core/styles");

var _Button = _interopRequireDefault(require("@material-ui/core/Button"));

var _translator = _interopRequireDefault(require("../translator"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var translator = _translator["default"].translator;

var buttonStyles = function buttonStyles(theme) {
  return {
    root: {
      backgroundColor: _renderUi.color.background(),
      color: _renderUi.color.text(),
      border: "1px solid ".concat(_renderUi.color.secondary()),
      '&:hover': {
        backgroundColor: _renderUi.color.secondaryLight()
      },
      fontSize: theme.typography.fontSize
    },
    selected: {
      backgroundColor: _renderUi.color.background(),
      '& span': {
        color: _renderUi.color.primaryDark()
      }
    },
    notSelected: {
      '& span': {
        color: _renderUi.color.primary()
      },
      backgroundColor: _renderUi.color.background()
    },
    disabled: {
      '& span': {
        color: _renderUi.color.primary()
      },
      backgroundColor: _renderUi.color.disabled()
    }
  };
};

var MiniButton = (0, _styles.withStyles)(buttonStyles)(function (props) {
  var disabled = props.disabled,
      classes = props.classes,
      className = props.className,
      selected = props.selected,
      value = props.value,
      onClick = props.onClick;
  return /*#__PURE__*/_react["default"].createElement(_Button["default"], {
    size: "small",
    disabled: disabled,
    color: selected ? 'secondary' : 'default',
    className: (0, _classnames["default"])(classes.root, selected && classes.selected, className),
    classes: {
      disabled: (0, _classnames["default"])(disabled && classes.disabled)
    },
    value: value,
    key: value,
    variant: "outlined",
    onClick: onClick
  }, value);
});
exports.MiniButton = MiniButton;
MiniButton.propTypes = {
  disabled: _propTypes["default"].bool,
  className: _propTypes["default"].string,
  disabledClassName: _propTypes["default"].string,
  selected: _propTypes["default"].bool,
  value: _propTypes["default"].string,
  onClick: _propTypes["default"].func
};

var ToolMenu = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(ToolMenu, _React$Component);

  var _super = _createSuper(ToolMenu);

  function ToolMenu() {
    (0, _classCallCheck2["default"])(this, ToolMenu);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(ToolMenu, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          className = _this$props.className,
          disabled = _this$props.disabled,
          addCategory = _this$props.addCategory,
          language = _this$props.language;
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: (0, _classnames["default"])(className)
      }, !disabled && /*#__PURE__*/_react["default"].createElement(MiniButton, {
        value: translator.t('charting.addCategory', {
          lng: language
        }),
        onClick: addCategory
      }));
    }
  }]);
  return ToolMenu;
}(_react["default"].Component);

exports.ToolMenu = ToolMenu;
(0, _defineProperty2["default"])(ToolMenu, "propTypes", {
  className: _propTypes["default"].string,
  addCategory: _propTypes["default"].func,
  disabled: _propTypes["default"].bool,
  language: _propTypes["default"].string
});
(0, _defineProperty2["default"])(ToolMenu, "defaultProps", {});
var _default = ToolMenu;
exports["default"] = _default;
//# sourceMappingURL=tool-menu.js.map