"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 _react = _interopRequireDefault(require("react"));
var _Focusable = require("../common/Focusable");
var _generateDataAttr = require("../utils/generateDataAttr");
var _Badge = require("./Badge.constants");
var _BadgeSt = require("./Badge.st.css.js");
var _Text = _interopRequireDefault(require("../Text/Text"));
var _excluded = ["focusableOnFocus", "focusableOnBlur"],
  _excluded2 = ["type", "skin", "size", "uppercase", "noPadding", "showTooltip", "display", "children", "prefixIcon", "suffixIcon", "onClick", "dataHook", "className", "ariaLabel"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Badge/Badge.tsx";
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; }
var getProps = props => {
  // that's what you pay for using HOCs...
  var {
      focusableOnFocus,
      focusableOnBlur
    } = props,
    rest = (0, _objectWithoutProperties2.default)(props, _excluded);
  return rest;
};
var getFocusableProps = props => {
  // add focusable hooks only when badge is clickable
  var {
    onClick,
    focusableOnFocus,
    focusableOnBlur
  } = props;
  return onClick ? {
    onFocus: focusableOnFocus,
    onBlur: focusableOnBlur,
    tabIndex: 0
  } : {};
};
function Badge(props) {
  var _getProps = getProps(props),
    {
      type = _Badge.TYPE.solid,
      skin = _Badge.SKIN.general,
      size = _Badge.SIZE.medium,
      uppercase = true,
      noPadding = false,
      showTooltip = true,
      display = 'inline',
      children,
      prefixIcon,
      suffixIcon,
      onClick,
      dataHook,
      className,
      ariaLabel
    } = _getProps,
    rest = (0, _objectWithoutProperties2.default)(_getProps, _excluded2);
  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
    "aria-label": ariaLabel,
    role: onClick ? 'button' : undefined,
    "data-hook": dataHook,
    onClick: onClick,
    onKeyDown: onClick ? event => {
      if (event.key === 'Enter' || event.key === ' ') {
        event.preventDefault();
        onClick(event);
      }
    } : undefined
  }, getFocusableProps(props), {
    className: (0, _BadgeSt.st)(_BadgeSt.classes.root, _objectSpread({
      clickable: !!onClick,
      display,
      type,
      skin,
      size,
      uppercase,
      noPadding
    }, rest), className)
  }, (0, _generateDataAttr.generateDataAttr)({
    type,
    skin,
    size,
    uppercase
  }, ['type', 'skin', 'size', 'uppercase']), {
    "data-clickable": !!onClick
    /* TODO: this prop used to come from stylable v1 spread and is used for testing. Update component testkit to use stylable testkit instead */,
    "data-is-inverted": rest['data-is-inverted'],
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 54,
      columnNumber: 5
    }
  }), prefixIcon && /*#__PURE__*/_react.default.cloneElement(prefixIcon, {
    className: _BadgeSt.classes.prefix,
    'data-prefix-icon': true
  }), /*#__PURE__*/_react.default.createElement(_Text.default, {
    className: _BadgeSt.classes.text,
    ellipsis: true,
    size: size === 'medium' ? 'small' : size,
    weight: "normal",
    showTooltip: showTooltip,
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 100,
      columnNumber: 7
    }
  }, children), suffixIcon && /*#__PURE__*/_react.default.cloneElement(suffixIcon, {
    className: _BadgeSt.classes.suffix,
    'data-suffix-icon': true
  }));
}
Badge.displayName = 'Badge';
var _default = exports.default = (0, _Focusable.withFocusable)(Badge);
//# sourceMappingURL=Badge.js.map