import { Component } from 'react';
import PropTypes from 'prop-types';
import { addEventHandlersManually, getNonEventHandlerProps } from '../../utils/events';
import getModifiedProps from '../../utils/getModifiedProps';

class Chart extends Component {

  static propTypes = {
    type: PropTypes.string.isRequired,
    width: PropTypes.number,
    height: PropTypes.number,
    onAddSeries: PropTypes.func,
    onAfterPrint: PropTypes.func,
    onBeforePrint: PropTypes.func,
    onClick: PropTypes.func,
    onLoad: PropTypes.func,
    onRedraw: PropTypes.func,
    onRender: PropTypes.func,
    onSelection: PropTypes.func,
    getChart: PropTypes.func.isRequired, // Provided by ChartProvider
    getHighcharts: PropTypes.func.isRequired // Provided by HighchartsProvider
  };

  static defaultProps = {
    type: 'line',
    onAddSeries: () => {},
    onAfterPrint: () => {},
    onBeforePrint: () => {},
    onClick: () => {},
    onLoad: () => {},
    onRedraw: () => {},
    onRender: () => {},
    onSelection: () => {}
  };

  componentDidMount () {
    const { getHighcharts, getChart, needsRedraw, children, ...rest } = this.props;
    const notEventProps = getNonEventHandlerProps(rest);
    const chart = getChart();

    this.updateChart({
      ...notEventProps
    });

    addEventHandlersManually(getHighcharts(), chart.object, rest);
  }

  componentDidUpdate (prevProps) {
    const modifiedProps = getModifiedProps(prevProps, this.props);
    if (modifiedProps !== false) {
      this.updateChart(modifiedProps);
    }
  }

  updateChart = config => {
    const chart = this.props.getChart();
    chart.update({
      chart: config
    }, false);
    this.props.needsRedraw();
  }

  render () {
    return null;
  }
}

export default Chart;

@@ -334,44 +334,162 @@
 pes.
-number,%0A    height: PropTypes.number
+oneOfType(%5B%0A      PropTypes.string,%0A      PropTypes.number%0A    %5D),%0A    height: PropTypes.oneOfType(%5B%0A      PropTypes.string,%0A      PropTypes.number%0A    %5D)
 ,%0A  

Fix chart width and height proptypes