import _Message from "./_Message.js";

var Messages = function(){
  return {
    view: function(vnode){
      return m('.messages-box.p-fixed.p-2', {style: 'left:0px;top:0px;width:100%;'},_Message.messages.map(function(msg, index){
        var message_class;
        if(msg.type === 'success'){
          message_class = 'toast-success';
          }
        else if(msg.type === 'notification'){
          message_class = 'toast-primary';
          }
        else if(msg.type === 'error'){
          message_class = 'toast-error';
          }
        return m('.toast.'+message_class, [
          m('button.btn.btn-clear.float-right', {onclick: function(){ _Message.remove(index); }}, ""),
          msg.text
          ]);
        }));
      }
    };
  };

export default Messages;