import React__default from 'react';
import { K } from './index.module-d24badee.js';
import { T as TOKEN_TYPES, U as USER_MENTION_PREFIX, g as getWhiteSpacePreservedText } from './tokenize-d12690c3.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-f50d7ab0.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-a31ee68d.js.map
