import React__default from 'react';
import { a as LabelTypography } from '../index-f50d7ab0.js';
import LinkLabel from './LinkLabel.js';
import { u as uuidv4 } from '../uuid-8b344dd2.js';
import { P as convertWordToStringObj, S as StringObjType } from '../index-99ab01f6.js';
import MentionLabel from './MentionLabel.js';
import 'prop-types';
import '../stringSet-e9bb0333.js';
import '../_rollupPluginBabelHelpers-cc035350.js';
import '../utils/message/getOutgoingMessageState.js';
import './ContextMenu.js';
import 'react-dom';
import './SortByRow.js';
import './UserProfile.js';
import '../LocalizationContext-1701e5c8.js';
import '../index-ff8f2f61.js';
import '../UserProfileContext-74e9a128.js';
import '../sendbirdSelectors.js';
import '../topics-0b30f52b.js';
import '../utils-05aa9060.js';
import './Avatar.js';
import './ImageRenderer.js';
import './Icon.js';
import './Button.js';
import '../useSendbirdStateContext.js';
import '../withSendbird.js';

/**
 * @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.createElement("span", {
    className: "sendbird-word"
  }, 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 === StringObjType.mention) {
      return /*#__PURE__*/React__default.createElement(MentionLabel, {
        mentionTemplate: mentionTemplate,
        mentionedUserId: userId,
        mentionedUserNickname: value,
        key: uuidv4(),
        isByMe: isByMe
      });
    } else if (type === 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.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
