import React, { Component } from 'react';
import PropTypes from 'prop-types';

import {
  StyleSheet,
  Text,
  View,
} from 'react-native';

export default class Events extends Component {
  static get propTypes() {
    return {
      events: PropTypes.array.isRequired,
      fetchEvents: PropTypes.func.isRequired,
    };
  }

  constructor(props) {
    super(props);
  }

  componentDidMount() {
    this.props.fetchEvents();
  }

  _keyExtractor = (event, index) => `${event._id}_${index}`;

  _renderEventListItem = ({ event }) => <EventListItem event={event} />;

  render() {
    const { events } = this.props;

    return (
      <View style={styles.container}>
        {events.size > 0 && (
          <FlatList
            data={events}
            keyExtractor={this._keyExtractor}
            renderItem={this._renderEventListItem}
            contentContainerStyle={styles.eventListContentContainer}
            style={styles.eventList}
          />
        )}
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  eventListContentContainer: {
  },
});
