class Day extends React.Component {

    constructor(props) {
        super(props);
        this.state = {};
    }

    selectDate(){
        var month = (this.props.month + 1).toString();
        var day = this.props.date.toString();

        if(month.length==1){
            month = '0' + month;
        }

        if(day.length==1){
            day = '0' + day;
        }
        this.props.selectDate(new Date(this.props.year + '-' + month + '-' + day));
    }

    render() {

        var result;

        if(this.props.date==''){
            result = (
                <td>
                    {this.props.date}
                </td>
            )
        }else{
            if(this.props.selectedDate.getMonth()==this.props.month && this.props.selectedDate.getDate()==this.props.date){
                result = (
                    <td className="day-of-month selected">
                        {this.props.date}
                    </td>
                )
            }else{
                result = (
                    <td className="day-of-month" onClick={(e) => this.selectDate(e)}>
                        {this.props.date}
                    </td>
                )
            }
        }

        return result;
    }
}