import 'whatwg-fetch';
import Cascader from '..';
import React from 'react';
import ReactDOM from 'react-dom';
interface PageStates {
  dataSource: Array<any>;
}
const dataSource = [
  {
    value: '2973',
    label: '陕西',
  },
];
class Demo extends React.Component<{}, PageStates> {
  constructor(props) {
    super(props);

    this.state = {
      dataSource,
    };

    this.onLoadData = this.onLoadData.bind(this);
  }

  onLoadData(data) {
    console.log(data);

    return new Promise(() => {
      setTimeout(() => {
        this.setState({
          dataSource: [
            {
              value: '2973',
              label: '陕西',
              children: [
                {
                  value: '2974',
                  label: '西安',
                  children: [
                    { value: '2975', label: '西安市', isLeaf: true },
                    { value: '2976', label: '高陵县', isLeaf: true },
                  ],
                },
                {
                  value: '2980',
                  label: '铜川',
                  children: [
                    { value: '2981', label: '铜川市', isLeaf: true },
                    { value: '2982', label: '宜君县', isLeaf: true },
                  ],
                },
              ],
            },
          ],
        });
      }, 500);
    });
  }

  render() {
    return (
      <Cascader
        canOnlySelectLeaf
        dataSource={this.state.dataSource}
        loadData={this.onLoadData}
      />
    );
  }
}
ReactDOM.render(<Demo />, document.getElementById('cascader-demo-5'));
