import * as React from 'react';
import { withRouter, RouteChildrenProps } from 'react-router-dom';
import Risk from './riskinfo'
import PlainList from './plain';
import FlowList from './flow';
import agent from '../Server';
import Rank from './rank';
/** Props接口 */
interface IProps {

}

class UIComponents extends React.Component<IProps & RouteChildrenProps, any> {

    constructor(props) {
        super(props);
        this.state = {
            radioValue: props.location.query?.radio,
            enabled: false
        };
    }
    radioChange = (value) => {
        this.setState({
            radioValue: value
        })
    }


    componentDidMount() {
        this.getData()

    }
    getData = async () => {
        const res: any = await agent.post('/web/verifierparty/riskconfig/get', {}, this);
        if (res.err) {
            return;
        } else {
            if (res.res.enabled) {
                this.setState({
                    enabled: res.res.enabled,
                    radioValue: this.state.radioValue || 'customer'
                })
            } else {
                this.setState({
                    enabled: res.res.enabled,
                    radioValue: this.state.radioValue || 'list'
                })
            }

        }
    }


    render() {
        const { radioValue, enabled } = this.state;
        return (
            <div style={{ height: 'calc(100vh - 97px)', display: 'flex', flexDirection: 'column' }}>
                {radioValue === 'customer' && <Risk changeView={this.radioChange} />}
                {radioValue === 'list' && <PlainList enabled={enabled} changeView={this.radioChange} />}
                {radioValue === 'echart' && <FlowList enabled={enabled} changeView={this.radioChange} />}
                {radioValue === 'rank' && <Rank enabled={enabled} changeView={this.radioChange} />}
            </div>
        );
    }
}

export default withRouter(UIComponents as any)