import * as React from 'react';
import classNames from 'classnames';
import { isEmpty } from '@aws-amplify/ui';
import { MessageButtonProps } from '@aws-amplify/ui-react-core-notifications';
import {
Button,
ButtonGroup,
Flex,
Heading,
Image,
Text,
} from '@aws-amplify/ui-react';
import { CloseIconButton } from '../CloseIconButton';
import {
BLOCK_CLASS,
BODY_TEXT_TEST_ID,
BUTTON_CLASS,
BUTTON_GROUP_TEST_ID,
CLOSE_BUTTON_CLASS,
CONTENT_CLASS,
CONTENT_TEST_ID,
HEADER_CLASS,
HEADER_TEXT_TEST_ID,
IMAGE_CONTAINER_CLASS,
IMAGE_CONTAINER_TEST_ID,
MESSAGE_LAYOUT_TEST_ID,
PRIMARY_BUTTON_TEST_ID,
SECONDARY_BUTTON_TEST_ID,
TEXT_CONTAINER_CLASS,
TEXT_CONTAINER_TEST_ID,
} from './constants';
import { MessageLayoutProps } from './types';
import { getButtonModifier } from './utils';
const isMessageButton = (button: unknown): button is MessageButtonProps =>
!isEmpty(button);
export function MessageLayout({
body,
buttonSize,
hasRenderableImage,
header,
image,
onClose,
orientation = 'vertical',
primaryButton,
secondaryButton,
styles,
}: MessageLayoutProps): JSX.Element {
const buttonModifiers = React.useMemo(
() => ({
primary: getButtonModifier(styles.primaryButton),
secondary: getButtonModifier(styles.secondaryButton),
}),
[styles]
);
const isHorizontal = orientation === 'horizontal';
const closeButton = (
);
const hasPrimaryButton = isMessageButton(primaryButton);
const hasSecondaryButton = isMessageButton(secondaryButton);
const hasButtons = hasPrimaryButton || hasSecondaryButton;
return (
{!isHorizontal && {closeButton}}
{hasRenderableImage && (
)}
{header?.content && (
{header.content}
)}
{body?.content && (
{body.content}
)}
{isHorizontal && {closeButton}}
{hasButtons && (
{hasSecondaryButton && (
)}
{hasPrimaryButton && (
)}
)}
);
}