import React from 'react';
import { WeaTools, WeaLeftRightLayout } from 'ecCom';

import './style/';
import MaterialLibLeft from './MaterialLibLeft';
import MaterialLibRight from './MaterialLibRight';

class MaterialLib extends React.Component {
    state = { visible: true, hasRight: false, dir: 'image/' };

    constructor(props) {
        super(props);
        this.setVisible = this.setVisible.bind(this);
        this.setDir = this.setDir.bind(this);
    }

    componentWillMount() {
        WeaTools.callApi('/api/portal/materialLib/getRightStatus', 'GET', {}).then((result) => {
            this.setState({ hasRight: result.right_status == 1 });
        });
    }

    render() {
        const { multiCheck } = this.props;
        const { visible, hasRight, dir } = this.state;

        return (
            visible ?
                <WeaLeftRightLayout
                  leftWidth={220}
                  showLeft={true}
                  leftCom={<MaterialLibLeft hasRight={hasRight} setDir={this.setDir} />}
                  children={<MaterialLibRight ref="mlr" hasRight={hasRight} dir={dir} multiCheck={multiCheck} />}
                /> : ''
        );
    }

    setVisible(visible) {
        this.setState({ visible });
    }

    setDir(dir) {
        this.setState({ dir });
    }

    getCheckedFiles() {
        return this.refs.mlr.getCheckedFiles();
    }
}

export default MaterialLib;
