"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/ColorPickerConverterHsb.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 ColorPickerConverterHsb = exports["default"] = /*#__PURE__*/function (_React$PureComponent) {
  function ColorPickerConverterHsb() {
    var _this;
    (0, _classCallCheck2["default"])(this, ColorPickerConverterHsb);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, ColorPickerConverterHsb, [].concat(args));
    _this.state = (0, _utils.getHsbOrEmpty)(_this.props.current);
    return _this;
  }
  (0, _inherits2["default"])(ColorPickerConverterHsb, _React$PureComponent);
  return (0, _createClass2["default"])(ColorPickerConverterHsb, [{
    key: "isInputsEmpty",
    value: function isInputsEmpty() {
      var _this$state = this.state,
        h = _this$state.h,
        s = _this$state.s,
        l = _this$state.l;
      return [h, s, l].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.h,
        onChange: function onChange(e) {
          return _this2.change('h', e);
        },
        placeholder: "H",
        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.s,
        onChange: function onChange(e) {
          return _this2.change('s', e);
        },
        placeholder: "S",
        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.l,
        onChange: function onChange(e) {
          return _this2.change('l', 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.getHsbOrEmpty)(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 _this3$state = _this3.state,
          h = _this3$state.h,
          s = _this3$state.s,
          l = _this3$state.l;
        var isMissingData = [h, s, l].some(function (_value) {
          return _value === '';
        });
        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);