"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _raven = _interopRequireDefault(require("@wii/raven"));
var _message = _interopRequireDefault(require("../message"));
require("./style");
const wauMessage = {
  raven: new _raven.default()
};
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.default[type](content, duration, onClose);
    }
  };
});
wauMessage.open = args => {
  if (wauMessage.raven.isChild) {
    wauMessage.raven.send('toast', args);
  } else {
    return _message.default.open(args);
  }
};
wauMessage.warn = wauMessage.warning;
wauMessage.config = _message.default.config;
wauMessage.destroy = _message.default.destroy;
wauMessage.useMessage = _message.default.useMessage;
var _default = wauMessage;
exports.default = _default;