import React from 'react';
import PropTypes from 'prop-types';
import './Message.scss';
import Linkify from 'linkifyjs/react';
import ReactMarkdown from 'react-markdown';
import gfm from 'remark-gfm';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { coy } from 'react-syntax-highlighter/dist/esm/styles/prism';
import Text from '../../atoms/text/Text';
import RawIcon from '../../atoms/system-icons/RawIcon';
import Avatar from '../../atoms/avatar/Avatar';
import ReplyArrowIC from '../../../../public/res/ic/outlined/reply-arrow.svg';
const components = {
code({
// eslint-disable-next-line react/prop-types
inline, className, children,
}) {
const match = /language-(\w+)/.exec(className || '');
return !inline && match ? (
{String(children).replace(/\n$/, '')}
) : (
{String(children)}
);
},
};
function linkifyContent(content) {
return {content};
}
function genMarkdown(content) {
return {content};
}
function PlaceholderMessage() {
return (
);
}
function Message({
color, avatarSrc, name, content,
time, markdown, contentOnly, reply,
edited, reactions,
}) {
const msgClass = contentOnly ? 'message--content-only' : 'message--full';
return (
{ !contentOnly && (
)}
{ reply !== null && (
{reply.to}
<>{` ${reply.content}`}>
)}
{ markdown ? genMarkdown(content) : linkifyContent(content) }
{ edited &&
(edited)}
{ reactions && (
{
reactions.map((reaction) => (
))
}
)}
);
}
Message.defaultProps = {
color: 'var(--tc-surface-high)',
avatarSrc: null,
markdown: false,
contentOnly: false,
reply: null,
edited: false,
reactions: null,
};
Message.propTypes = {
color: PropTypes.string,
avatarSrc: PropTypes.string,
name: PropTypes.string.isRequired,
content: PropTypes.node.isRequired,
time: PropTypes.string.isRequired,
markdown: PropTypes.bool,
contentOnly: PropTypes.bool,
reply: PropTypes.shape({
color: PropTypes.string.isRequired,
to: PropTypes.string.isRequired,
content: PropTypes.string.isRequired,
}),
edited: PropTypes.bool,
reactions: PropTypes.arrayOf(PropTypes.exact({
id: PropTypes.string,
key: PropTypes.string,
count: PropTypes.number,
active: PropTypes.bool,
})),
};
export { Message as default, PlaceholderMessage };