import ViewUI from "view-design";
let errorTipMinTime = 3;
let msgInstance = null;
let resetMessage = {
  destroy: ViewUI.Message.destroy
};
["error", "success", "info", "warning", "loading", "config"].forEach((type) => {
  resetMessage[type] = (options) => {
    if (msgInstance) {
      ViewUI.Message.destroy();
    }
    if (type === "error" || type === "warning") {
      if (typeof options === "string") {
        options = {
          content: options,
          duration: errorTipMinTime
        };
      } else {
        if (options.duration !== 0) {
          options.duration =
            options.duration > errorTipMinTime
              ? options.duration
              : errorTipMinTime;
        }
      }
    }
    msgInstance = ViewUI.Message[type](options);
  };
});
export const message = resetMessage;
