import React__default from 'react';
import { a as LabelTypography } from '../index-67c5e94c.js';
import LinkLabel from './LinkLabel.js';
import { u as uuidv4 } from '../uuid-9f7da91d.js';
import { k as convertWordToStringObj, S as StringObjType } from '../index-8ee9e1f5.js';
import MentionLabel from './MentionLabel.js';
import 'prop-types';
import '../stringSet-ad8993d1.js';
import '../tslib.es6-cd680863.js';
import '../utils/message/getOutgoingMessageState.js';
import './ContextMenu.js';
import 'react-dom';
import './SortByRow.js';
import './UserProfile.js';
import '../LocalizationContext-a6aa8be8.js';
import '../index-757a563a.js';
import '../UserProfileContext-dd096494.js';
import '../sendbirdSelectors.js';
import '../topics-9fbe0d61.js';
import '../utils-aae15fda.js';
import './Avatar.js';
import './ImageRenderer.js';
import './Icon.js';
import './Button.js';
import '../useSendbirdStateContext.js';
import '../withSendbird.js';
import '../_rollupPluginBabelHelpers-3e5825fa.js';

function Word(props) {
  var word = props.word,
      message = props.message,
      _a = props.isByMe,
      isByMe = _a === void 0 ? false : _a,
      _b = props.mentionTemplate,
      mentionTemplate = _b === void 0 ? '@' : _b,
      _c = props.renderString,
      renderString = _c === void 0 ? null : _c;

  if (word === '') {
    return null;
  }

  return /*#__PURE__*/React__default.createElement("span", {
    className: "sendbird-word"
  }, convertWordToStringObj(word, message === null || message === void 0 ? void 0 : message.mentionedUsers).map(function (stringObj) {
    var _a;

    var type = (stringObj === null || stringObj === void 0 ? void 0 : stringObj.type) || '';
    var value = (stringObj === null || stringObj === void 0 ? void 0 : stringObj.value) || '';
    var userId = (stringObj === null || stringObj === void 0 ? void 0 : stringObj.userId) || '';

    if (renderString && typeof renderString === 'function') {
      return renderString(stringObj);
    }

    if (type === StringObjType.mention) {
      return /*#__PURE__*/React__default.createElement(MentionLabel, {
        mentionTemplate: mentionTemplate,
        mentionedUserId: userId,
        mentionedUserNickname: value,
        key: uuidv4(),
        isByMe: isByMe
      });
    } else if (type === StringObjType.url) {
      var urlRegex = new RegExp("([a-zA-Z0-9]+://)?([a-zA-Z0-9_]+:[a-zA-Z0-9_]+@)?([a-zA-Z0-9.-]+\\.[A-Za-z]{2,4})(:[0-9]+)?(/.*)?");
      var targetUrl = (_a = urlRegex.exec(value)) === null || _a === void 0 ? void 0 : _a[0];
      var stringUrl = {
        front: '',
        url: '',
        back: ''
      };

      if (targetUrl) {
        var 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.createElement(LinkLabel, {
          className: "sendbird-word__url",
          key: uuidv4(),
          src: stringUrl.url,
          type: LabelTypography.BODY_1
        }, stringUrl.url) : null, stringUrl.back ? stringUrl.back : ''];
      }

      return /*#__PURE__*/React__default.createElement(LinkLabel, {
        className: "sendbird-word__url",
        key: uuidv4(),
        src: word,
        type: LabelTypography.BODY_1
      }, value);
    } else {
      return value;
    }
  }));
}

export { Word as default };
//# sourceMappingURL=Word.js.map
