"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = exports.RawTextDefaultProps = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _react = _interopRequireWildcard(require("react"));
var _TextSt = require("./Text.st.css.js");
var _context = require("../WixStyleReactMaskingProvider/context");
var _excluded = ["size", "secondary", "skin", "light", "weight", "tagName", "children", "ellipsis", "appendTo", "flip", "fixed", "placement", "maxWidth", "zIndex", "showTooltip", "listStyle", "id", "widows", "suffix", "overflowWrap", "renderChildren", "renderElement"],
  _excluded2 = ["dataHook", "className"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/Text/RawText.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); }
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 getStyleDataAttributes = styleAttributes => Object.keys(styleAttributes).reduce((acc, styleKey) => {
  acc["data-".concat(styleKey)] = styleAttributes[styleKey];
  return acc;
}, {});
var RawTextDefaultProps = exports.RawTextDefaultProps = {
  size: 'medium',
  secondary: false,
  skin: 'standard',
  light: false,
  weight: 'thin',
  tagName: 'span',
  listStyle: 'checkmark',
  widows: false,
  overflowWrap: 'normal'
};
var RawText = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
  var {
      size = RawTextDefaultProps.size,
      secondary = RawTextDefaultProps.secondary,
      skin = RawTextDefaultProps.skin,
      light = RawTextDefaultProps.light,
      weight = RawTextDefaultProps.weight,
      tagName = RawTextDefaultProps.tagName,
      children,
      ellipsis,
      appendTo,
      flip,
      fixed,
      placement,
      maxWidth,
      zIndex,
      showTooltip,
      listStyle = RawTextDefaultProps.listStyle,
      id,
      widows = RawTextDefaultProps.widows,
      suffix,
      overflowWrap = RawTextDefaultProps.overflowWrap,
      renderChildren,
      renderElement
    } = _ref,
    rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
  var {
      dataHook,
      className
    } = rest,
    textProps = (0, _objectWithoutProperties2.default)(rest, _excluded2);
  var styleAttributes = {
    size,
    secondary,
    skin,
    light,
    weight,
    widows,
    'list-style': listStyle,
    'overflow-wrap': overflowWrap
  };
  var styleDataAttributes = getStyleDataAttributes(styleAttributes);
  var childrenWidows = (0, _react.useMemo)(() => {
    if (!widows || typeof children !== 'string' || !children) {
      return children;
    }
    var textArray = children.split(' ');
    if (textArray.length <= 2) return children;
    var arrLength = textArray.length;
    var newChildrenArr = textArray.slice(0, arrLength - 2);
    newChildrenArr.push(textArray[arrLength - 2] + '\u00A0' + textArray[arrLength - 1]);
    return newChildrenArr.join(' ');
  }, [children, widows]);
  return /*#__PURE__*/_react.default.createElement(_context.WixStyleReactMaskingContext.Consumer, {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 105,
      columnNumber: 7
    }
  }, _ref2 => {
    var {
      maskingClassNames
    } = _ref2;
    var element = /*#__PURE__*/_react.default.createElement(tagName, _objectSpread(_objectSpread({
      ref,
      id
    }, textProps), {}, {
      'data-hook': dataHook,
      'data-mask': !!maskingClassNames,
      className: (0, _TextSt.st)(_TextSt.classes.root, styleAttributes, className, maskingClassNames)
    }, styleDataAttributes), renderChildren({
      text: childrenWidows,
      suffix
    }));
    return renderElement({
      element,
      suffix
    });
  });
});
RawText.displayName = 'Text';
var _default = exports.default = RawText;
//# sourceMappingURL=RawText.js.map