"use strict";
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {ListGroup, ListGroupItem} from 'react-bootstrap';
import * as stateActions from 'actions/stateActions';
import {Panel} from 'react-bootstrap';
import i18n from 'i18n.json';

class Week extends React.Component {
    constructor()
    {
        super();
        let weekData = Week.getDays();

        this.currentDay = weekData.current;
        this.week       = weekData.week;
    }

    componentDidMount()
    {
        this.props.stateActions.setHeader(i18n[lang].choose_day);

        if (!window.__WeekOneMount)
        {
            window.__WeekOneMount = true;
            //this.props.router.push('/day/' + this.currentDay);
        }
    }

    static getDays()
    {
        return {
            current: new Date().getDay(),
            week   : [
                i18n[lang].sunday,
                i18n[lang].monday,
                i18n[lang].tuesday,
                i18n[lang].wednesday,
                i18n[lang].thursday,
                i18n[lang].friday,
                i18n[lang].saturday
            ]
        };
    }

    goToDay(i)
    {
        this.props.router.push('/day/' + i);
    }

    render()
    {
        return (
            <Panel id="content-wrap" header={this.props.header}>
                <ListGroup fill>
                    {this.week.map(
                        (weekday, i) => <ListGroupItem onClick={this.goToDay.bind(this, i)} ref={'day-' + i} key={i}>{weekday}</ListGroupItem>
                    )}
                </ListGroup>
            </Panel>
        );
    }
}

export default connect(
    state =>
    {
        return {
            week  : state.state.week,
            header: state.state.panel.header
        }
    },

    dispatch =>
    {
        return {
            stateActions: bindActionCreators(stateActions, dispatch)
        }
    }
)(Week)