import { Text } from '@tarojs/components';

import { useCallback } from 'react';

import BaseMessage, { IUserMessageProps } from '@/components/message-chat/base';
import { copy } from '@/utils/common';
import Toast from '@/utils/toast';

import './index.less';

interface IProps extends IUserMessageProps {}

const PREFIX = 'text-message';

function TextMessage(props: IProps) {
  const { message } = props;

  const handleLongPress = useCallback(async () => {
    await copy(message.content);
    Toast.success('复制成功');
  }, [message.content]);

  return (
    <BaseMessage {...props}>
      <Text className={`${PREFIX}__content`} onLongPress={handleLongPress}>
        {message.content}
      </Text>
    </BaseMessage>
  );
}

export default TextMessage;
