import Raven from '@wii/raven';
import message from '../message';
import './style';
const wauMessage = {
  raven: new Raven()
};
const messageTypes = ['success', 'info', 'error', 'loading', 'warning'];
function formatContent(content) {
  if (typeof content === 'string') {
    return {
      content
    };
  } else {
    return content;
  }
}
function sendToast(type, content, duration) {
  const formattedContent = formatContent(content);
  wauMessage.raven.send('toast', {
    ...formattedContent,
    type,
    duration
  });
}
messageTypes.forEach(type => {
  wauMessage[type] = (content, duration, onClose) => {
    if (wauMessage.raven.isChild) {
      sendToast(type, content, duration);
    } else {
      return message[type](content, duration, onClose);
    }
  };
});
wauMessage.open = args => {
  if (wauMessage.raven.isChild) {
    wauMessage.raven.send('toast', args);
  } else {
    return message.open(args);
  }
};
wauMessage.warn = wauMessage.warning;
wauMessage.config = message.config;
wauMessage.destroy = message.destroy;
wauMessage.useMessage = message.useMessage;
export default wauMessage;