import React__default from 'react';
import { K } from './index.module-2885df8c.js';
import { T as TOKEN_TYPES, U as USER_MENTION_PREFIX, g as getWhiteSpacePreservedText } from './tokenize-b97bc343.js';
import { useMessageContext } from './Message/context.js';
import MentionLabel from './ui/MentionLabel.js';
import LinkLabel from './ui/LinkLabel.js';
import { a as LabelTypography } from './index-4372fcec.js';

// this function is used to generate a unique key for token in message
// it changes with updated time and index
// messageUpdatedAt is the key part of this key generator
function keyGenerator(createdAt, messageUpdatedAt, index) {
  return `sb-msg_${createdAt}_${messageUpdatedAt}_${index}`;
}

function TextFragment(_ref) {
  let {
    tokens
  } = _ref;
  const messageStore = useMessageContext();
  const message = messageStore === null || messageStore === void 0 ? void 0 : messageStore.message;
  const isByMe = messageStore === null || messageStore === void 0 ? void 0 : messageStore.isByMe;
  const {
    updatedAt,
    createdAt
  } = message;
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, tokens === null || tokens === void 0 ? void 0 : tokens.map((token, idx) => {
    const key = keyGenerator(createdAt, updatedAt, idx);
    return K(token.type).with(TOKEN_TYPES.mention, () => /*#__PURE__*/React__default.createElement("span", {
      className: "sendbird-word",
      key: key
    }, /*#__PURE__*/React__default.createElement(MentionLabel, {
      mentionTemplate: USER_MENTION_PREFIX,
      mentionedUserId: token.userId,
      mentionedUserNickname: token.value,
      isByMe: isByMe
    }))).with(TOKEN_TYPES.url, () => /*#__PURE__*/React__default.createElement("span", {
      className: "sendbird-word",
      key: key
    }, /*#__PURE__*/React__default.createElement(LinkLabel, {
      className: "sendbird-word__url",
      src: token.value,
      type: LabelTypography.BODY_1
    }, token.value))).otherwise(() => /*#__PURE__*/React__default.createElement(React__default.Fragment, {
      key: key
    }, getWhiteSpacePreservedText(token.value)));
  }));
}

export { TextFragment as T };
//# sourceMappingURL=index-8aa7880e.js.map
