import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
/** @jsx jsx */
import React, { PureComponent } from 'react';
import { jsx } from '@emotion/react';
import EditorDoneIcon from '@atlaskit/icon/glyph/editor/done';
import { N0 } from '@atlaskit/theme/colors';
import Tooltip from '@atlaskit/tooltip';
import { buttonStyle, buttonWrapperStyle } from './styles';
var Color = /*#__PURE__*/function (_PureComponent) {
  _inherits(Color, _PureComponent);
  var _super = _createSuper(Color);
  function Color() {
    var _this;
    _classCallCheck(this, Color);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _super.call.apply(_super, [this].concat(args));
    _defineProperty(_assertThisInitialized(_this), "onMouseDown", function (e) {
      e.preventDefault();
    });
    _defineProperty(_assertThisInitialized(_this), "onClick", function (e) {
      var _this$props = _this.props,
        onClick = _this$props.onClick,
        value = _this$props.value,
        label = _this$props.label;
      e.preventDefault();
      onClick(value, label);
    });
    return _this;
  }
  _createClass(Color, [{
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
        autoFocus = _this$props2.autoFocus,
        tabIndex = _this$props2.tabIndex,
        value = _this$props2.value,
        label = _this$props2.label,
        isSelected = _this$props2.isSelected,
        borderColor = _this$props2.borderColor,
        _this$props2$checkMar = _this$props2.checkMarkColor,
        checkMarkColor = _this$props2$checkMar === void 0 ? N0 : _this$props2$checkMar,
        hexToPaletteColor = _this$props2.hexToPaletteColor;
      var colorStyle = hexToPaletteColor ? hexToPaletteColor(value) : value;
      return jsx(Tooltip, {
        content: label
      }, jsx("span", {
        css: buttonWrapperStyle
      }, jsx("button", {
        type: "button",
        css: buttonStyle,
        "aria-label": label,
        role: "radio",
        "aria-checked": isSelected,
        onClick: this.onClick,
        onMouseDown: this.onMouseDown,
        tabIndex: tabIndex,
        className: "".concat(isSelected ? 'selected' : ''),
        style: {
          backgroundColor: colorStyle || 'transparent',
          border: "1px solid ".concat(borderColor)
        },
        autoFocus: autoFocus
      }, isSelected && jsx(EditorDoneIcon, {
        primaryColor: checkMarkColor,
        label: ""
      }))));
    }
  }]);
  return Color;
}(PureComponent);
export default Color;