import React, { useState, useEffect } from 'react';
import TextWrapper from './TextWrapper';
import { useSelector } from 'react-redux';
import GPTIcon from '../svg/GPTIcon';
import BingIcon from '../svg/BingIcon';
import HoverButtons from './HoverButtons';
import Spinner from '../svg/Spinner';
export default function Message({
sender,
text,
last = false,
error = false,
scrollToBottom
}) {
const { isSubmitting } = useSelector((state) => state.submit);
const [abortScroll, setAbort] = useState(false);
const notUser = sender.toLowerCase() !== 'user';
const blinker = isSubmitting && last && notUser;
useEffect(() => {
if (blinker && !abortScroll) {
scrollToBottom();
}
}, [isSubmitting, text, blinker, scrollToBottom, abortScroll]);
if (sender === '') {
return ;
}
const handleWheel = () => {
if (blinker) {
setAbort(true);
} else {
setAbort(false);
}
};
const props = {
className:
'w-full border-b border-black/10 dark:border-gray-900/50 text-gray-800 bg-white dark:text-gray-100 group dark:bg-gray-800'
};
const bgColors = {
chatgpt: 'rgb(16, 163, 127)',
chatgptBrowser: 'rgb(25, 207, 207)',
bingai: '',
sydney: ''
};
const isBing = sender === 'bingai' || sender === 'sydney';
let icon = `${sender}:`;
let backgroundColor = bgColors[sender];
if (notUser) {
props.className =
'w-full border-b border-black/10 bg-gray-50 dark:border-gray-900/50 text-gray-800 dark:text-gray-100 group bg-gray-100 dark:bg-[#444654]';
}
if ((notUser && backgroundColor) || isBing) {
icon = (
{isBing ? : }
{error && (
!
)}
);
}
const wrapText = (text) => ;
return (
{typeof icon === 'string' && icon.match(/[^\u0000-\u007F]+/) ? (
{icon}
) : (
icon
)}
{error ? (
) : (
{/*
*/}
{notUser ? wrapText(text) : text}
{blinker && █}
)}
);
}