import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as ContactsActions from 'cem/actions/contacts';

import styles from 'cem/styles/header';

// import Filter from 'cem/components/contacts/list/filter';
import Card from 'cem/components/contacts/card';

import UI from 'cem/components/ui';
const { Grid } = UI;

class ListContainer extends Component {
  componentWillMount() {
    this.props.actions.loadList();
  }

  render() {
    const { list: { items = [], isFetching } } = this.props.state.contacts;

    return (
      <section>
        <Grid.Container fluid>
          <div className={styles.header}>
            <Grid.Row>
              <Grid.Col xs="20">
                <h1 className={styles.title}>
                  Контакты <UI.Button className={styles.btnAdd} to="/contacts/create" kind="success">добавить</UI.Button>
                </h1>
              </Grid.Col>
            </Grid.Row>
            <Grid.Row>
              {/* <Filter /> */}
            </Grid.Row>
          </div>
        </Grid.Container>

        {!items.length && !isFetching && <h2 className={styles.titleNotFound}>Не найдено контактов</h2>}
        {items.map(contact => <Card contact={contact} key={contact.id} />)}
      </section>
    );
  }
}

const pickState = ({ contacts }) => ({
  state: { contacts },
});

const pickActions = (dispatch) => ({
  actions: bindActionCreators(ContactsActions, dispatch),
});

export default connect(pickState, pickActions)(ListContainer);
