import {
    WeaPopoverHrm,
    WeaLocaleProvider,
    WeaTools
} from 'ecCom';
import {
    WeaLogView
} from 'comsMobx';
import {
    isEnableMultiLang
} from '../apis/common';
import loadjs from 'loadjs';
const WeaLogViewComp = WeaLogView.Component;
const {
    LogStore
} = WeaLogView;

class Home extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            key: new Date().getTime(),
            visible: false,
            logStore: new LogStore(),
            logType: '4',
            logSmallType: '',
            // comsLoaded: false
        }
        window.setLogViewProps = this.setLogViewProps;
    }

    componentDidMount() {
        isEnableMultiLang().then(data => {
            window.inputType = {
                inputType: 'NORMAL'
            }
            if (data.status === '1') {
                if (data.isEnableMultiLang) {
                    window.inputType = {
                        inputType: 'MULTILANG',
                        isBase64: true
                    }
                }
            }
        }, error => {
            window.inputType = {
                inputType: 'NORMAL'
            }
        });
        // loadjs.isDefined('hrmComs') ? loadjs.ready('hrmComs', () => this.setState({comsLoaded: true})) : loadjs(["/spa/hrm/static4coms/hrmComs.js", "/spa/hrm/static4coms/hrmComs.css"], 'hrmComs', () => this.setState({comsLoaded: true}));
    }

    setLogViewProps = (props) => {
        this.setState({
            key: new Date().getTime(),
            targetId: '',
            visible: true,
            logType: '4',
            logStore: new LogStore(),
            ...props
        });
    }
    onCancel = () => {
        this.setState({
            visible: false
        })
    }
    render() {
        return (
            <div style={{height:"100%"}}>
                <WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@bvqmtf`} />
                <WeaLogViewComp ecId={`${this && this.props && this.props.ecId || ''}_WeaLogViewComp@llhywc`} {...this.state} onCancel={this.onCancel}/>
                <WeaLocaleProvider ecId={`${this && this.props && this.props.ecId || ''}_WeaLocaleProvider@qydj45`}>
                {/* {this.state.comsLoaded && this.props.children} */}
                {this.props.children}
                </WeaLocaleProvider>
            </div>
        )
    }
}

export default Home