"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _styles = require("../styles");
var _react = require("react");
var _native = require("@react-navigation/native");
const RenderTextWithMention = ({
  mentionPositionArr,
  textPost
}) => {
  const styles = (0, _styles.useStyles)();
  const navigation = (0, _native.useNavigation)();
  if (mentionPositionArr.length === 0) {
    return /*#__PURE__*/React.createElement(_reactNative.Text, {
      style: styles.inputText
    }, textPost);
  }
  const mentionClick = userId => {
    navigation.navigate('UserProfile', {
      userId: userId
    });
  };
  let currentPosition = 0;
  const result = mentionPositionArr.map(({
    index,
    length,
    userId
  }, i) => {
    // Add non-highlighted text before the mention
    const nonHighlightedText = textPost.slice(currentPosition, index);

    // Add highlighted text
    const highlightedText = /*#__PURE__*/React.createElement(_reactNative.Text, {
      onPress: () => mentionClick(userId),
      key: `highlighted-${i}`,
      style: styles.mentionText
    }, textPost.slice(index, index + length));

    // Update currentPosition for the next iteration
    currentPosition = index + length;

    // Return an array of non-highlighted and highlighted text
    return [nonHighlightedText, highlightedText];
  });

  // Add any remaining non-highlighted text after the mentions
  const remainingText = textPost.slice(currentPosition);
  result.push([/*#__PURE__*/React.createElement(_reactNative.Text, {
    key: "nonHighlighted-last",
    style: styles.inputText
  }, remainingText)]);

  // Flatten the array and render
  return /*#__PURE__*/React.createElement(_reactNative.Text, {
    style: styles.inputText
  }, result.flat());
};
var _default = exports.default = /*#__PURE__*/(0, _react.memo)(RenderTextWithMention);
//# sourceMappingURL=RenderTextWithMention.js.map