import React, { Component } from 'react';
import hocImmutable, { imShallowEqual } from '../../utils/HOC/hocImmutable';
import { Checkbox } from 'antd';

export default hocImmutable(class extends Component {
    constructor(props) {
        super(props);
    }
    state = {
        value: this.props.value || this.props.defaultValue || []
    }
    onChange = value => {
        const { onChange } = this.props;
        this.setState({ value }, () => {
            onChange && onChange(value)
        })
    }
    componentWillReceiveProps(nextProps) {
        if (this.state.value != nextProps.value) {
            this.setState({ value: nextProps.value })
        }
    }
    render() {
        const { onChange, ...props } = this.props;
        return <Checkbox.Group {...props}
            key={'comp-checkbox-group-rnd-' + Date.now()}
            value={this.state.value}
            onChange={this.onChange}
        />
    }
})