"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
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 _Focusable = require("../common/Focusable");
var _wixUiIconsCommon = require("@wix/wix-ui-icons-common");
var _FillButtonSt = require("./FillButton.st.css.js");
var _Tooltip = _interopRequireDefault(require("../Tooltip"));
var _Proportion = _interopRequireDefault(require("../Proportion"));
var _constants = require("./constants");
var _utils = require("./utils");
var _IconThemeContext = require("../WixDesignSystemIconThemeProvider/IconThemeContext");
var _excluded = ["disabled", "focusableOnBlur", "focusableOnFocus", "dataHook", "fill", "iconSize", "tooltipContent", "tooltipProps", "className"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/FillButton/FillButton.jsx";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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 iconSmall = _constants.dataHooks.iconSmall,
  iconMedium = _constants.dataHooks.iconMedium;

/** FillButton */
var FillButton = /*#__PURE__*/function (_React$PureComponent) {
  function FillButton() {
    var _this;
    (0, _classCallCheck2["default"])(this, FillButton);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, FillButton, [].concat(args));
    _this._getBackground = function (fill) {
      var disabled = _this.props.disabled;
      if ((0, _utils.parseColor)(fill) && !disabled) {
        return {
          backgroundColor: fill
        };
      }
      if ((0, _utils.parseGradient)(fill) && !disabled) {
        return {
          backgroundImage: fill
        };
      }
      return undefined;
    };
    _this._renderIcon = function () {
      var _icons$FillButton, _icons$FillButton2;
      var icons = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var _this$props = _this.props,
        iconSize = _this$props.iconSize,
        fill = _this$props.fill,
        disabled = _this$props.disabled,
        icon = _this$props.icon;
      var iconStyle = {
        color: !disabled && (0, _utils.parseContrastColor)(fill)
      };
      if (icon) {
        return /*#__PURE__*/_react["default"].cloneElement(icon, {
          style: iconStyle
        });
      }
      var AddIcon = iconSize === 'small' ? ((_icons$FillButton = icons.FillButton) == null ? void 0 : _icons$FillButton.AddSmall) || _wixUiIconsCommon.AddSmall : ((_icons$FillButton2 = icons.FillButton) == null ? void 0 : _icons$FillButton2.Add) || _wixUiIconsCommon.Add;
      return /*#__PURE__*/_react["default"].createElement(AddIcon, {
        style: iconStyle,
        "data-hook": iconSize === 'small' ? iconSmall : iconMedium,
        __self: _this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 51,
          columnNumber: 7
        }
      });
    };
    return _this;
  }
  (0, _inherits2["default"])(FillButton, _React$PureComponent);
  return (0, _createClass2["default"])(FillButton, [{
    key: "render",
    value: function render() {
      var _this2 = this;
      var _this$props2 = this.props,
        disabled = _this$props2.disabled,
        focusableOnBlur = _this$props2.focusableOnBlur,
        focusableOnFocus = _this$props2.focusableOnFocus,
        dataHook = _this$props2.dataHook,
        fill = _this$props2.fill,
        iconSize = _this$props2.iconSize,
        tooltipContent = _this$props2.tooltipContent,
        _this$props2$tooltipP = _this$props2.tooltipProps,
        tooltipProps = _this$props2$tooltipP === void 0 ? {} : _this$props2$tooltipP,
        className = _this$props2.className,
        rest = (0, _objectWithoutProperties2["default"])(_this$props2, _excluded);
      var background = this._getBackground(fill);

      // For backwards compatibility
      var content = tooltipProps.content || tooltipContent;
      return /*#__PURE__*/_react["default"].createElement(_IconThemeContext.IconThemeContext.Consumer, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 77,
          columnNumber: 7
        }
      }, function (_ref) {
        var _ref$icons = _ref.icons,
          icons = _ref$icons === void 0 ? {} : _ref$icons;
        return /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], (0, _extends2["default"])({
          appendTo: "window",
          disabled: disabled
        }, tooltipProps, {
          content: content,
          dataHook: dataHook,
          size: "small",
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 79,
            columnNumber: 11
          }
        }), /*#__PURE__*/_react["default"].createElement(_Proportion["default"], {
          className: _FillButtonSt.classes.proportion,
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 87,
            columnNumber: 13
          }
        }, /*#__PURE__*/_react["default"].createElement("button", (0, _extends2["default"])({}, rest, {
          className: (0, _FillButtonSt.st)(_FillButtonSt.classes.root, {
            disabled: disabled,
            fill: !!background
          }, className),
          style: _objectSpread({}, background),
          "data-hook": _constants.dataHooks.button,
          onFocus: focusableOnFocus,
          onBlur: focusableOnBlur,
          disabled: disabled,
          type: "button",
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 88,
            columnNumber: 15
          }
        }), _this2._renderIcon(icons))));
      });
    }
  }]);
}(_react["default"].PureComponent);
FillButton.displayName = 'FillButton';
FillButton.defaultProps = {
  iconSize: 'small'
};
var _default = exports["default"] = (0, _Focusable.withFocusable)(FillButton);