import React from 'react';
import { ServiceAgent } from 'grey-service-agent';
import { Switch, Route, MemoryRouter, Redirect } from 'react-router-dom';

import TaskAdd from '../MasterTask/add';
import TaskView from '../MasterTask/detail';
import SlaveTaskAdd from '../SlaveTask/add'
import SlaveTaskView from '../SlaveTask/detail';
// import SlaveConnectView from '../SlaveTask/connectView';
// import SlaveConnectEdit from '../SlaveTask/connectEdit';
import Entry from './UI.Component';
import SlaveEntry from './UI.ComponentSlave';
import MasterConfig from './UI.MasterConfig';
import CompanyDetail from '../MasterRiskCompanyDetail';
import CompanyLawDetail from '../MasterRiskCompanyLawDetail';
import { ConfigProvider } from "kts-xui";
import zh_CN from 'kts-components-antd-x4/es/locale-provider/zh_CN';
// import { ConfigProvider } from 'kts-components-antd-x4';
import { LocaleProvider } from 'antd';
// import zhCN1 from 'kts-components-antd-x4/lib/locale/zh_CN';
import zhCN from 'antd/lib/locale-provider/zh_CN';
declare const RollType: ["master", "slave", "master_config", "slave_config"];
export declare type RollType = typeof RollType[number];
export interface DigitalAssetVerificationProps {
    /** 通信模块 */
    server: ServiceAgent
    prefix: string;
    serviceTools: any;
    /**
     * master代表审核方；slave代表被审核方
     */
    role?: RollType;
    remoteConfig?: {
        domain: string,
        token: string,
    }
    didPath?: string;
    pathname?: string;
    user?: {
        userInfo: {
            nickName: string
        }
    };
}
class DigitalAssetVerification extends React.Component<DigitalAssetVerificationProps>{

    static server: ServiceAgent;
    static prefix_path = '';
    static rootPath = '';
    static remoteConfig = { domain: '', token: '' };
    // TODO 独立部署暂时没有serviceTools尽快实现
    static serviceTools: any;
    /**
     * 跳转的did应用地址
     */
    static didPath = ''
    /**
    * master代表审核方；slave代表被审核方
    */
    static role = 'master' || 'slave';

    static pathname = '';

    static user: any;

    constructor(props: DigitalAssetVerificationProps) {
        super(props)
        DigitalAssetVerification.prefix_path = props.prefix || '';
        DigitalAssetVerification.server = props.server;
        DigitalAssetVerification.role = props.role || 'slave';
        DigitalAssetVerification.serviceTools = props.serviceTools;
        DigitalAssetVerification.didPath = props.didPath || '';
        DigitalAssetVerification.pathname = props.pathname || '/task/list/verify';
        DigitalAssetVerification.user = props.user;
        // DigitalAssetVerification.remoteConfig = props.remoteConfig;
    }

    render() {
        const pathname = DigitalAssetVerification.pathname;
        return (
            <MemoryRouter >
                <ConfigProvider locale={zh_CN as any}>
                    <LocaleProvider locale={zhCN}>
                        {
                            DigitalAssetVerification.role === 'master' &&
                            <Switch>
                                <Route path="/task/list" component={Entry} />
                                <Route path='/task/masteradd/:id?' component={TaskAdd} />
                                <Route path='/task/edit/:id' component={TaskAdd} />
                                {/* <Route path='/task/view/:id' component={TaskView} /> */}
                                <Route path='/task/slaveadd/:id/:type' component={SlaveTaskAdd} />
                                <Route path='/task/slaveview/:id' component={SlaveTaskView} />
                                <Route path='/task/masterview/:id' component={TaskView} />
                                <Route path='/task/risk/company/detail/:id/:company/:tab?' component={CompanyDetail} />
                                <Route path='/task/risk/company/law/detail/:id' component={CompanyLawDetail} />
                                <Route render={() => <Redirect to={pathname} />} />
                            </Switch>
                        }
                        {
                            DigitalAssetVerification.role === 'slave' &&
                            <Switch>
                                <Route path="/task/list" component={SlaveEntry} />
                                <Route path='/task/slaveadd/:id/:type' component={SlaveTaskAdd} />
                                <Route path='/task/masterview/:id' component={TaskView} />
                                {/* <Route path='/task/slaveview/:id' component={SlaveTaskView} /> */}
                                <Route path='/task/slaveview/:id/:type?' component={SlaveTaskView} />
                                <Route render={() => <Redirect to={pathname} />} />
                            </Switch>
                        }

                        {
                            DigitalAssetVerification.role === 'master_config' &&
                            <Switch>
                                <Route path="/config" component={MasterConfig} />
                                <Route render={() => <Redirect to='/config' />} />
                            </Switch>

                        }
                    </LocaleProvider>
                </ConfigProvider>
            </MemoryRouter>
        )
    }
}

export default DigitalAssetVerification;