import React from 'react';
import { connect } from 'react-redux';
import { clearMessage } from '../../actions/notice';

import Notice from './notices/Notice';

class Notices extends React.Component {
  clear() {
    this.props.clearMessage();
  }

  render () {
    if (this.props.notice.messages.length <= 0) {
      return null;
    }

    return (
      <div className="notices">
        {this.props.notice.messages.map((notice, index) => <Notice key={`notice-${index}`} notice={notice}/>)}
      </div>
    );
  }
}

export default connect(
  (state) => ({ notice: state.notice }),
  { clearMessage },
)(Notices)
