"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var _Input = _interopRequireDefault(require("../Input"));
var _ColorPickerConverterSt = require("./ColorPickerConverter.st.css.js");
var _ColorPickerConverterViewer = _interopRequireDefault(require("./ColorPickerConverterViewer"));
var _utils = require("./utils");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/ColorPicker/ColorPickerConverterRGB.jsx";
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var ColorPickerConverterRGB = exports["default"] = /*#__PURE__*/function (_React$PureComponent) {
  function ColorPickerConverterRGB() {
    var _this;
    (0, _classCallCheck2["default"])(this, ColorPickerConverterRGB);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, ColorPickerConverterRGB, [].concat(args));
    _this.state = (0, _utils.getRgbOrEmpty)(_this.props.current);
    return _this;
  }
  (0, _inherits2["default"])(ColorPickerConverterRGB, _React$PureComponent);
  return (0, _createClass2["default"])(ColorPickerConverterRGB, [{
    key: "isInputsEmpty",
    value: function isInputsEmpty() {
      var _this$state = this.state,
        r = _this$state.r,
        g = _this$state.g,
        b = _this$state.b;
      return [r, g, b].every(function (value) {
        return value === '';
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;
      var dataHook = this.props.dataHook;
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: (0, _ColorPickerConverterSt.st)(_ColorPickerConverterSt.classes.colorConverterWrapper, {
          reducePadding: true
        }),
        "data-hook": dataHook,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 19,
          columnNumber: 7
        }
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: _ColorPickerConverterSt.classes.distribute,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 25,
          columnNumber: 9
        }
      }, /*#__PURE__*/_react["default"].createElement(_Input["default"], {
        size: "medium",
        value: this.state.r,
        onChange: function onChange(e) {
          return _this2.change('r', e);
        },
        placeholder: "R",
        className: _ColorPickerConverterSt.classes.distributedItem,
        onInputClicked: _utils.stopPropagation,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 26,
          columnNumber: 11
        }
      }), /*#__PURE__*/_react["default"].createElement(_Input["default"], {
        size: "medium",
        value: this.state.g,
        onChange: function onChange(e) {
          return _this2.change('g', e);
        },
        placeholder: "G",
        className: _ColorPickerConverterSt.classes.distributedItem,
        onInputClicked: _utils.stopPropagation,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 34,
          columnNumber: 11
        }
      }), /*#__PURE__*/_react["default"].createElement(_Input["default"], {
        size: "medium",
        value: this.state.b,
        onChange: function onChange(e) {
          return _this2.change('b', e);
        },
        placeholder: "B",
        className: _ColorPickerConverterSt.classes.distributedItem,
        onInputClicked: _utils.stopPropagation,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 42,
          columnNumber: 11
        }
      })), /*#__PURE__*/_react["default"].createElement(_ColorPickerConverterViewer["default"], (0, _extends2["default"])({}, this.props, {
        color: this.props.current,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 51,
          columnNumber: 9
        }
      })));
    }
  }, {
    key: "UNSAFE_componentWillReceiveProps",
    value: function UNSAFE_componentWillReceiveProps(props) {
      this.setState((0, _utils.getRgbOrEmpty)(props.current));
    }
  }, {
    key: "change",
    value: function change(part, _ref) {
      var _this3 = this;
      var value = _ref.target.value;
      this.setState((0, _defineProperty2["default"])({}, part, value), function () {
        var isMissingData = _this3.state.r === '' || _this3.state.g === '' || _this3.state.b === '';
        var _color = (0, _utils.safeColor)(isMissingData && _this3.props.allowEmpty ? '' : _this3.state, _this3.props.allowEmpty);
        if (!isMissingData || _this3.isInputsEmpty()) {
          _this3.props.onChange(_color);
        }
      });
    }
  }]);
}(_react["default"].PureComponent);