import * as React from 'react';
import IOption from './IOption';
import { ExcelImport, ScanImport, OcrScanerImport, ImageImport, AdvanceManualImport, RuleImport,CommonExcel } from './InvoiceTab';

/** 组建的props接口 */
interface IProps {
    urlData: IOption;
    refreshInvoice: () => void;
    onClose: () => void;
    currentActive: string;
}

export default class UIComponents extends React.Component<IProps, any> {

    /** 构造函数 */
    constructor(props: IProps) {
        super(props);
    }

    handleCancel = () => {
        this.props.onClose && this.props.onClose();
    }

    renderCurrentTab = () => {
        const { refreshInvoice, urlData, currentActive } = this.props;
        switch (currentActive) {
            case 'scangun':
                // 扫码枪
                return <ScanImport fnForceUpdate={refreshInvoice} url={urlData} />;
            case 'excel':
                // Excel上传
                return <ExcelImport fnForceUpdate={refreshInvoice} data={{ url: urlData.url!, downloadurl: urlData.downloadurl! }} />
            case 'image':
                // 影像/版式文件
                return <ImageImport fnForceUpdate={refreshInvoice} url={urlData} />;
            case 'manual':
                // 手工录入
                return <AdvanceManualImport handleCancel={this.handleCancel} fnForceUpdate={refreshInvoice} data={urlData} />;
            case 'scanner':
                // 扫描仪
                return <OcrScanerImport fnForceUpdate={refreshInvoice} url={urlData} />
            case 'rule':
                return <RuleImport fnForceUpdate={refreshInvoice} data={{ url: urlData.rule! }} />
            case 'commonexcel':
                return <CommonExcel fnForceUpdate={refreshInvoice} data={urlData} />
        }
    }
    render() {
        return (
            <div>
                {this.renderCurrentTab()}
            </div>
        );
    }
}
