import React from 'react';
import { Select } from 'antd';

const Yearselect = React.createClass({
    getInitialState: function () {
        return { theOption: [] };
    },
    onChange(e) {
        this.props.handleyear(e);
        this.setState({
            Year:e
        });
    },
    componentWillMount() {
        const Option = Select.Option;
        const d = new Date();
        const thisYear = d.getFullYear();
        this.state.thisYear = d.getFullYear();

        for (let i = thisYear; i >= 1950; i--) {
            this.state.theOption.push(<Option key={i.toString()}>{i}</Option>)
        };
        this.state.defYear = this.state.thisYear.toString();
    },
    componentWillUpdate(nextProps){
        if ( nextProps.defValue ) {
            this.state.Year = nextProps.defValue;
        };
    },
    render() {
        return (
            <Select value={this.state.Year} className="year-select" onChange={this.onChange}>
                {this.state.theOption}
            </Select>
        )
    }
});

export default Yearselect;