"use strict";

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

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

var _classnames = _interopRequireDefault(require("classnames"));

var _getLocale = require("../../../utils/getLocale");

require("./index.css");

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var precls = 'titaui-rect-btn';

function RectBtn(props) {
  var _props$type = props.type,
      type = _props$type === void 0 ? 'default' : _props$type,
      _props$icon = props.icon,
      icon = _props$icon === void 0 ? '' : _props$icon,
      _props$text = props.text,
      text = _props$text === void 0 ? (0, _getLocale.getLocale)('OKR_MyO_Butt_Determine') : _props$text,
      _props$size = props.size,
      size = _props$size === void 0 ? 'normal' : _props$size,
      _props$onClick = props.onClick,
      onClick = _props$onClick === void 0 ? function () {} : _props$onClick,
      _props$className = props.className,
      className = _props$className === void 0 ? '' : _props$className,
      _props$disabled = props.disabled,
      disabled = _props$disabled === void 0 ? false : _props$disabled,
      _props$loading = props.loading,
      loading = _props$loading === void 0 ? false : _props$loading,
      style = props.style,
      children = props.children;

  var renderIcon = function renderIcon() {
    if (typeof icon === 'string') {
      return /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(precls, "__icon")
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: icon
      }));
    }

    return /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(precls, "__icon")
    }, icon);
  };

  var onClickHandler = function onClickHandler(e) {
    if (disabled || loading) return;

    if (onClick) {
      onClick(e);
    }
  };

  return /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])(precls, "".concat(precls, "--").concat(type), "".concat(precls, "--").concat(size), _defineProperty({}, "".concat(precls, "--disabled"), disabled || loading), className),
    style: style,
    onClick: onClickHandler
  }, icon && renderIcon(), children || text);
}

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