"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _CounterBadgeSt = require("./CounterBadge.st.css.js");
var _Caption = _interopRequireDefault(require("../Text/Caption"));
var _Text = _interopRequireDefault(require("../Text"));
var _constants = require("./constants");
var _context = require("../WixStyleReactEnvironmentProvider/context");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/CounterBadge/CounterBadge.tsx";
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var MAX_NUMBER = 100;
/** CounterBadge */
class CounterBadge extends _react.PureComponent {
  constructor() {
    super(...arguments);
    this.context = void 0;
    this._renderNumberContent = (n, truncate) => n < MAX_NUMBER || !truncate ? Intl.NumberFormat(this._getLocale()).format(n) : /*#__PURE__*/_react.default.createElement("div", {
      className: _CounterBadgeSt.classes.numberContent,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 32,
        columnNumber: 7
      }
    }, MAX_NUMBER - 1, /*#__PURE__*/_react.default.createElement("svg", {
      xmlns: "http://www.w3.org/2000/svg",
      width: "5",
      height: "5",
      viewBox: "0 0 5 5",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 34,
        columnNumber: 9
      }
    }, /*#__PURE__*/_react.default.createElement("path", {
      fill: "currentColor",
      d: "M3,0 L3,2 L5,2 L5,3 L3,3 L3,5 L2,5 L2,3 L0,3 L0,2 L2,2 L2,0 L3,0 Z",
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 40,
        columnNumber: 11
      }
    })));
    this._renderCounterBadgeContent = (size, content) => size === 'small' ? /*#__PURE__*/_react.default.createElement(_Caption.default, {
      tagName: "span",
      caption: "c1",
      light: true,
      dataHook: _constants.dataHooks.content,
      className: _CounterBadgeSt.classes.caption,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 53,
        columnNumber: 7
      }
    }, content) : /*#__PURE__*/_react.default.createElement(_Text.default, {
      dataHook: _constants.dataHooks.content,
      size: "tiny",
      weight: "bold",
      light: true,
      className: _CounterBadgeSt.classes.text,
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 63,
        columnNumber: 7
      }
    }, content);
  }
  _getLocale() {
    return this.props.locale || this.context.locale || 'en';
  }
  render() {
    var {
      dataHook,
      size,
      skin,
      children,
      className,
      showShadow,
      truncate
    } = this.props;
    var custom = isNaN(Number(children));
    var longNumber = !custom && truncate && Number(children) >= MAX_NUMBER;
    var content = custom ? children : this._renderNumberContent(Number(children), truncate);
    return /*#__PURE__*/_react.default.createElement("div", {
      className: (0, _CounterBadgeSt.st)(_CounterBadgeSt.classes.root, {
        skin,
        custom,
        size,
        longNumber,
        showShadow
      }, className),
      "data-hook": dataHook,
      "data-locale": this._getLocale(),
      __self: this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 89,
        columnNumber: 7
      }
    }, this._renderCounterBadgeContent(size, content));
  }
}
CounterBadge.displayName = 'CounterBadge';
CounterBadge.defaultProps = {
  skin: 'general',
  size: 'small',
  showShadow: false,
  truncate: true
};
CounterBadge.contextType = _context.WixStyleReactEnvironmentContext;
var _default = exports.default = CounterBadge;
//# sourceMappingURL=CounterBadge.js.map