import './demo4.css';
import 'whatwg-fetch';
import Cascader from '..';
import React from 'react';
import ReactDOM from 'react-dom';
interface PageStates {
  value: string;
  data: Array<any>;
}
class Demo extends React.Component<{}, PageStates> {
  handleChange: (value: any, data: any, extra: any) => void;
  constructor(props) {
    super(props);

    this.handleChange = (value, data, extra) => {
      console.log(value, data, extra);
    };
    this.state = {
      value: null,
      data: [],
    };
  }

  componentDidMount() {
    fetch('https://os.alipayobjects.com/rmsportal/ODDwqcDFTLAguOvWEolX.json')
      .then(response => response.json())
      .then(data => this.setState({ data, value: '2975' }))
      .catch(e => console.log(e));
  }

  render() {
    return (
      <div className="control-single-demo">
        <Cascader
          canOnlySelectLeaf
          dataSource={this.state.data}
          onChange={this.handleChange}
        />
        <br />
        <br />
        <Cascader
          multiple
          canOnlyCheckLeaf
          dataSource={this.state.data}
          onChange={this.handleChange}
        />
      </div>
    );
  }
}
ReactDOM.render(<Demo />, document.getElementById('cascader-demo-4'));
