'use strict';

var React = require('react');
var ui_Label = require('../index-35633fb6.js');
var ui_LinkLabel = require('./LinkLabel.js');
var uuid = require('../uuid-1eceb0c8.js');
var index = require('../index-a91b85d9.js');
var ui_MentionLabel = require('./MentionLabel.js');
require('prop-types');
require('../stringSet-ce782136.js');
require('../_rollupPluginBabelHelpers-acf412a3.js');
require('../utils/message/getOutgoingMessageState.js');
require('./ContextMenu.js');
require('react-dom');
require('./SortByRow.js');
require('./UserProfile.js');
require('../LocalizationContext-8cc9717d.js');
require('../index-d749c4c2.js');
require('../UserProfileContext-d993c96b.js');
require('../sendbirdSelectors.js');
require('../topics-e24ef339.js');
require('../utils-5aa0708e.js');
require('./Avatar.js');
require('./ImageRenderer.js');
require('./Icon.js');
require('./Button.js');
require('../useSendbirdStateContext.js');
require('../withSendbird.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

/**
 * @deprecated  This component is deprecated and will be removed in the next major version.
 * Use TextFragment instead.
 */
// Word and StringObj will include types: normal, mention, url
function Word(props) {
  const {
    word,
    message,
    isByMe = false,
    mentionTemplate = '@',
    renderString = null
  } = props;
  if (word === '') {
    return null;
  }
  return /*#__PURE__*/React__default["default"].createElement("span", {
    className: "sendbird-word"
  }, index.convertWordToStringObj(word, message === null || message === void 0 ? void 0 : message.mentionedUsers).map(stringObj => {
    const type = (stringObj === null || stringObj === void 0 ? void 0 : stringObj.type) || '';
    const value = (stringObj === null || stringObj === void 0 ? void 0 : stringObj.value) || '';
    const userId = (stringObj === null || stringObj === void 0 ? void 0 : stringObj.userId) || '';
    if (renderString && typeof renderString === 'function') {
      return renderString(stringObj);
    }
    if (type === index.StringObjType.mention) {
      return /*#__PURE__*/React__default["default"].createElement(ui_MentionLabel, {
        mentionTemplate: mentionTemplate,
        mentionedUserId: userId,
        mentionedUserNickname: value,
        key: uuid.uuidv4(),
        isByMe: isByMe
      });
    } else if (type === index.StringObjType.url) {
      var _value$match;
      const urlRegex = /([a-zA-Z0-9]+:\/\/)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\.[A-Za-z]{2,4})(:[0-9]+)?(\/.*)?/;
      const targetUrl = (_value$match = value.match(urlRegex)) === null || _value$match === void 0 ? void 0 : _value$match[0];
      const stringUrl = {
        front: '',
        url: '',
        back: ''
      };
      if (targetUrl) {
        const targetUrlIndex = value.indexOf(targetUrl);
        if (targetUrlIndex > 0) {
          stringUrl.front = value.slice(0, targetUrlIndex);
        }
        stringUrl.url = value.slice(targetUrlIndex, targetUrlIndex + targetUrl.length);
        if (targetUrlIndex + targetUrl.length < value.length) {
          stringUrl.back = value.slice(targetUrlIndex + targetUrl.length);
        }
      }
      if (targetUrl) {
        return [stringUrl.front ? stringUrl.front : '', stringUrl.url ? /*#__PURE__*/React__default["default"].createElement(ui_LinkLabel["default"], {
          className: "sendbird-word__url",
          key: uuid.uuidv4(),
          src: stringUrl.url,
          type: ui_Label.LabelTypography.BODY_1
        }, stringUrl.url) : null, stringUrl.back ? stringUrl.back : ''];
      }
      return /*#__PURE__*/React__default["default"].createElement(ui_LinkLabel["default"], {
        className: "sendbird-word__url",
        key: uuid.uuidv4(),
        src: word,
        type: ui_Label.LabelTypography.BODY_1
      }, value);
    } else {
      return value;
    }
  }));
}

module.exports = Word;
//# sourceMappingURL=Word.js.map
