import { connect } from 'react-redux';

import { fetchEvents } from '../actions/events.js';
import EventRecord from '../domain/Event.js';
import { getActiveEvent, getDefaultEvent } from '../selectors/events.js';

import Event from './Event.js';

const matchStateToProps = (state) => {
    const event = getActiveEvent(state) || getDefaultEvent(state) || new EventRecord();

    if (!event) {
        return {};
    }

    return {
        description: event.get('description'),
        endTime: event.get('endTime'),
        id: event.get('id'),
        images: event.get('images').toArray(),
        isTicketed: event.get('isTicketed'),
        posts: event.get('posts').toArray(),
        requireLoginToSeeAuction: event.get('requireLoginToSeeAuction'),
        showFrom: event.get('showFrom'),
        showUntil: event.get('showUntil'),
        startTime: event.get('startTime'),
        tagline: event.get('tagline'),
        ticketClasses: event.get('ticketClasses').toArray(),
        title: event.get('title'),
        url: event.get('url'),
    };
};

const mapDispatchToProps = (dispatch) => ({});

export default connect(
    matchStateToProps,
    mapDispatchToProps,
)(Event);
