import React, { 
    Component
  } from 'react';
  import {
    WeaDialog,
    WeaRightMenu,
  } from "ecCom";
  import {
    Button,
  } from "antd";
  
  export default class DataShowDialog extends Component {

    getButton = () => {
      const {menus=[], disabled} = this.props;
      return menus && menus.map(item => <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@61fqte@DatashowDialogButton${item.key || item.type}`} 
        key={item.key || item.type} 
        type={"primary"} 
        disabled={disabled}
        onClick={() => this.onMenuClick(item.key || item.type)}
      >{item.content || item.menuName}</Button>);
    }

    getMenus = () => {
      const {menus=[], disabled} = this.props;
      return menus && menus.map(item => {
        return {
          key: item.key || item.type,
          icon: <i className={item.icon || item.menuIcon} />,
          content: item.content || item.menuName,
          disabled,
          onClick: () => this.onMenuClick(item.key || item.type),
        }
      });
    }

    onMenuClick = (type) => {
      if(this.props.onMenuClick && typeof(this.props.onMenuClick) === "function") {
        this.props.onMenuClick(type);
      }
    }

    onCancel = () => {
      if(this.props.onCancel && typeof(this.props.onCancel) === "function") {
        this.props.onCancel();
      }
    }

    render() {
      return (
        <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@1cf1pj`}
          visible={this.props.visible}
          title={this.props.title}
          moduleName={"integration"}
          style={this.props.style || {width: 800, height: 600}}
          hasScroll
          onCancel={this.onCancel}
          buttons={this.getButton()}
          moreBtn={{
            datas: this.getMenus(),
            collectParams: [],
          }}
        >
          <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@1kn5e9`} 
            datas={this.props.rightMenus || this.getMenus()}
            collectParams={[]}
          >
            {this.props.children}
          </WeaRightMenu>
        </WeaDialog>
      )
    }
  }
  