"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
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 = _interopRequireWildcard(require("react"));
var _react2 = require("@emotion/react");
var _done = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/done"));
var _colors = require("@atlaskit/theme/colors");
var _tooltip = _interopRequireDefault(require("@atlaskit/tooltip"));
var _styles = require("./styles");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /** @jsx jsx */
var Color = /*#__PURE__*/function (_PureComponent) {
  (0, _inherits2.default)(Color, _PureComponent);
  var _super = _createSuper(Color);
  function Color() {
    var _this;
    (0, _classCallCheck2.default)(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));
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMouseDown", function (e) {
      e.preventDefault();
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_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;
  }
  (0, _createClass2.default)(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 ? _colors.N0 : _this$props2$checkMar,
        hexToPaletteColor = _this$props2.hexToPaletteColor;
      var colorStyle = hexToPaletteColor ? hexToPaletteColor(value) : value;
      return (0, _react2.jsx)(_tooltip.default, {
        content: label
      }, (0, _react2.jsx)("span", {
        css: _styles.buttonWrapperStyle
      }, (0, _react2.jsx)("button", {
        type: "button",
        css: _styles.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 && (0, _react2.jsx)(_done.default, {
        primaryColor: checkMarkColor,
        label: ""
      }))));
    }
  }]);
  return Color;
}(_react.PureComponent);
var _default = exports.default = Color;