import { Text } from 'react-native';
import { useStyles } from '../styles';
import { memo } from 'react';
import { useNavigation } from '@react-navigation/native';
const RenderTextWithMention = ({
  mentionPositionArr,
  textPost
}) => {
  const styles = useStyles();
  const navigation = useNavigation();
  if (mentionPositionArr.length === 0) {
    return /*#__PURE__*/React.createElement(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(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(Text, {
    key: "nonHighlighted-last",
    style: styles.inputText
  }, remainingText)]);

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