import {SnackbarBody} from '@redux/events';
import {removeSnackbar, showSnackbar} from '@redux/dispatchers';
import {getUuid} from '@shared/utils';

let lastChatSnackbarId: Nullable<string> = null;

export const showChatSnackbar = (payload: Omit<SnackbarBody, 'id'>) => {
  if (lastChatSnackbarId) {
    removeSnackbar(lastChatSnackbarId);
  }
  const id = getUuid();
  lastChatSnackbarId = id;
  showSnackbar({...payload, id});
};
