import { memo, ReactNode } from 'react';

import Snackbar from '@mui/material/Snackbar';
import type { SnackbarProps } from '@mui/material/Snackbar';

import { Alert } from '../alert';
import type { AlertProps } from '../alert';

export interface SnackbarAlertProps extends Omit<SnackbarProps, 'children'> {
  /**
   * The content of the snackbar.
   */
  children?: ReactNode;
  /**
   * Props which will be forwarded into the Alert component. More info at https://mui.com/api/alert/
   */
  alertProps?: AlertProps;
}

const SnackbarAlert = (props: SnackbarAlertProps) => {
  const { alertProps, children, ...snackbarProps } = props;

  return (
    <Snackbar {...snackbarProps}>
      <Alert {...alertProps}>{children}</Alert>
    </Snackbar>
  );
};

SnackbarAlert.defaultProps = {
  alertProps: {}
};

const m = memo(SnackbarAlert);
export { m as SnackbarAlert };
