import React from 'react';
import { Button, Icon } from 'antd';
import { WeaLocaleProvider, WeaDialog, WeaRightMenu, WeaMoreButton, WeaNewScroll } from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
import PortalMenuTree from '../../../pc4backstage/portal4engine/components/portalmenu/PortalMenuTree';

class PortalMenu extends React.Component {
    state = { visible: false, type: 'left' };

    constructor(props) {
        super(props);
        this.getButtons = this.getButtons.bind(this);
        this.getRightMenus = this.getRightMenus.bind(this);
        this.onShow = this.onShow.bind(this);
        this.onAdd = this.onAdd.bind(this);
        this.onSave = this.onSave.bind(this);
        this.onCancel = this.onCancel.bind(this);
    }

    render() {
        const { visible, type } = this.state;

        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@87b9rg`}
              visible={visible}
              title={type == 'left' ? getLabel(33675, '前端菜单') : getLabel(33676, '后端菜单')}
              icon="icon-coms-portal"
              iconBgcolor="#1a57a0"
              style={{ width: 600, height: 500 }}
              hasScroll={true}
              buttons={this.getButtons()}
              onCancel={this.onCancel}
            >
                {visible ? <PortalMenuTree ecId={`${this && this.props && this.props.ecId || ''}_PortalMenuTree@2h0lte`} ref="portalmenutree" isCustom={true} type={type} /> : ''}
            </WeaDialog>
        );
    }

    getButtons() {
        let buttons = [];
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@9eg1ms`} type="primary" onClick={this.onAdd}>{getLabel(611, '添加')}</Button>);
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@wumcix`} type="primary" onClick={this.onSave}>{getLabel(30986, '保存')}</Button>);
        buttons.push(<WeaMoreButton ecId={`${this && this.props && this.props.ecId || ''}_WeaMoreButton@13k6as`} datas={this.getRightMenus()} />);
        return buttons;
    }

    getRightMenus() {
        let rightMenus = [];
        rightMenus.push({ key: '1', icon: <i className="icon-coms-Add-to-o" />, content: getLabel(611, '添加'), onClick: this.onAdd });
        rightMenus.push({ key: '2', icon: <i className="icon-coms-Preservation" />, content: getLabel(30986, '保存'), onClick: this.onSave });
        return rightMenus;
    }

    onShow(params) {
        this.setState({ visible: true, ...params });
    }

    onAdd() {
        this.refs.portalmenutree.wrappedInstance.onAdd2SubCompany();
    }

    onSave() {
        this.refs.portalmenutree.wrappedInstance.onSave();
    }

    onCancel() {
        this.setState({ visible: false });
    }
}

export default PortalMenu;
