import 'whatwg-fetch';
import Cascader from '..';
import React from 'react';
import ReactDOM from 'react-dom';
interface PageStates {
  label: string;
  data: Array<any>;
}
class Demo extends React.Component<{}, PageStates> {
  constructor(props) {
    super(props);

    this.state = {
      label: '',
      data: [],
    };

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

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

  handleChange(value, data, extra) {
    console.log(value, data, extra);

    this.setState({
      label: data.map(d => d.label).join(', '),
    });
  }

  render() {
    return (
      <div>
        <div
          className="cascader-value"
          style={{ width: '500px', fontSize: '14px', color: '#666' }}
        >
          Select: {this.state.label}
        </div>
        <Cascader
          multiple
          dataSource={this.state.data}
          onChange={this.handleChange}
        />
        <br/>
        <br/>
        <div style={{ background: '#f3f3f3', padding: '10px' }}>
          <Cascader
            theme='grey'
            multiple
            dataSource={this.state.data}
            onChange={this.handleChange}
          />
        </div>
      </div>
    );
  }
}
ReactDOM.render(<Demo />, document.getElementById('cascader-demo-3'));
