import React from "react";
import {inject, observer} from "mobx-react";
import { Button} from "antd";
import {toJS} from "mobx";
import {WeaForm, WeaLogView, WeaNewScroll, WeaSwitch, WeaTableNew} from "comsMobx";
import {WeaDialog, WeaLocaleProvider, WeaTools, WeaSearchGroup, WeaFormItem, WeaRightMenu,WeaTable} from "ecCom";
import * as IntegrationUtil from "../../util/IntegrationUtil";
const { getKey } = WeaTools;
const getLabel = WeaLocaleProvider.getLabel;

const store = ["oauth2Store"];

const transformArray = function (origin) {
  if (origin.length === 0) {
    return false;
  }
  return Object.keys(origin[0]).map(item => {
    return {
      title: origin[0][item],
      dataIndex: item,
      key: item,
    }
  })
}

@inject(...store)
@observer
export default class AppDataMappingImportResultDialog extends React.Component {
  render() {
    const {oauth2Store} = this.props;
    const status = toJS(oauth2Store.status);
    const {resultTableHeader,resultTableData} = toJS(status);

    return <WeaDialog
      title={getLabel('387020','数据映射导入结果')}
      onCancel={()=> oauth2Store.setState({appEditFormDetailDataMappingImportResultDialogVisible: false})}
      visible={status.appEditFormDetailDataMappingImportResultDialogVisible}
      style={{width: 700, height: 600}}
      hasScroll
      moduleName="integration"
      buttons={[
        <Button type="primary" onClick={()=> this.onRightMenuClick('BTN_SAVE')}>{getLabel( 309 ,'关闭')}</Button>
      ]}
      moreBtn={[]}
    >
      <WeaRightMenu
        datas={this.getRightMenu()}
        collectParams={[]}
      >
        <WeaSearchGroup center={false}  col={1}  needTigger={true} title={getLabel('82341','导入结果')} showGroup={true} items={[]}>
          <WeaTable columns={resultTableHeader?transformArray(resultTableHeader):[]} dataSource={resultTableData?resultTableData:[]} />
        </WeaSearchGroup>
      </WeaRightMenu>
    </WeaDialog>
  }

  getRightMenu() {
    let btnArr = [
      {
        key: 'BTN_SAVE',
        icon: <i className='icon-coms-go-back'/>,
        content : `${getLabel(309,'关闭')}`,
        onClick : () => {this.onRightMenuClick('BTN_SAVE')}
      }
    ];
    return btnArr;
  }
  
  onRightMenuClick = (type) => {
    const {oauth2Store} = this.props;
    const {registerAppEditForm,registerAppDataMappingImportForm, status} = oauth2Store;
    if(type == 'BTN_SAVE'){
      //关闭
      oauth2Store.setState({appEditFormDetailDataMappingImportResultDialogVisible: false});

    }

  }

}
