import styled from 'styled-components';
import { Text, Flex, Box, BoxProps, capitalizeFirstLetter } from '../../index';
import { BubbleAuthor } from './Bubble.styles';
import {
FragmentBlock,
FragmentPlain,
FragmentBlockquote,
renderFragment,
FragmentImage,
} from './fragment-lib';
import { FragmentImageType, FragmentType, TEXT_TYPES } from './Bubble.types';
const FullWidthFragmentBlock = styled(FragmentBlock)`
width: 100%;
`;
export type PinnedProps = {
id: string;
author: string;
authorColor?: string;
sentAt: string;
message?: FragmentType[];
onClick?: (msgId: string) => void;
} & BoxProps;
export const PinnedMessage = (props: PinnedProps) => {
const { id, author, authorColor, message, onClick = () => {} } = props;
if (!message) return null;
const fragmentType: string = Object.keys(message[0])[0];
let pinnedContent = null;
let mediaContent = null;
if (
(!TEXT_TYPES.includes(fragmentType) &&
fragmentType !== 'image' &&
fragmentType !== 'reply') ||
fragmentType === 'code'
) {
pinnedContent = (
{capitalizeFirstLetter(fragmentType)}
);
} else if (fragmentType === 'image') {
pinnedContent = (
{capitalizeFirstLetter(fragmentType)}
);
const link: string = (message[0] as FragmentImageType).image;
mediaContent = (
);
} else {
pinnedContent = renderFragment(id, message[0], 0, author);
}
return (
{mediaContent}
{author}
{pinnedContent}
);
};