"use strict";

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

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

var _reactColor = require("react-color");

var _indexModule = _interopRequireDefault(require("./index.module.less"));

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

var __extends = void 0 && (void 0).__extends || function () {
  var _extendStatics = function extendStatics(d, b) {
    _extendStatics = Object.setPrototypeOf || {
      __proto__: []
    } instanceof Array && function (d, b) {
      d.__proto__ = b;
    } || function (d, b) {
      for (var p in b) {
        if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
      }
    };

    return _extendStatics(d, b);
  };

  return function (d, b) {
    if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");

    _extendStatics(d, b);

    function __() {
      this.constructor = d;
    }

    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  };
}();

var ColorPicker =
/** @class */
function (_super) {
  __extends(ColorPicker, _super);

  function ColorPicker() {
    var _this = _super !== null && _super.apply(this, arguments) || this;

    _this.getRgbaStr = function (c) {
      return "rgba(".concat(c.r, ", ").concat(c.g, ", ").concat(c.b, ", ").concat(c.a, ")");
    };

    _this.getHexStr = function (c) {
      if (_this.getRgbaStr(c.rgb) === 'rgba(255, 255, 255, 0)') {
        return '';
      }

      return c.hex;
    };

    _this.onChangeColor = function (color) {
      var _a = _this.props,
          type = _a.type,
          onChangeColor = _a.onChangeColor;

      var _color = type === 'hex' ? _this.getHexStr(color) : _this.getRgbaStr(color.rgb);

      onChangeColor(_color);
    };

    return _this;
  }

  ColorPicker.prototype.render = function () {
    var _a = this.props,
        color = _a.color,
        visibility = _a.visibility,
        onClose = _a.onClose;
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: _indexModule["default"].colorPickerPanel
    }, visibility && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
      className: "panel-bg",
      onClick: function onClick() {
        return onClose();
      }
    }), /*#__PURE__*/_react["default"].createElement(_reactColor.SketchPicker, {
      color: color,
      disableAlpha: true,
      onChangeComplete: this.onChangeColor,
      presetColors: ['rgba(255,255,255,0)', '#000', '#fff', '#2F54EB', '#FF0000', '#FF7D00', '#FFFF00', '#00FF00', '#0000FF', '#FF00FF', '#EDF0F4', '#d9d9d9']
    })));
  };

  ColorPicker.defaultProps = {
    visibility: false,
    color: '#2F54EB',
    type: 'hex',
    onChangeColor: function onChangeColor() {},
    onClose: function onClose() {}
  };
  return ColorPicker;
}(_react["default"].Component);

var _default = ColorPicker;
exports["default"] = _default;