import React from "react";
import {inject, observer} from "mobx-react";
import { Button} from "antd";
import {toJS} from "mobx";
import {WeaDialog, WeaLocaleProvider, WeaSearchGroup, WeaRightMenu,WeaTable} from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;

const store = ["authenticationCenterStore"];

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 {authenticationCenterStore} = this.props;
    const status = toJS(authenticationCenterStore.status);
    const {resultTableHeader,resultTableData} = toJS(status);

    return <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@t6i8jt`}
      title={getLabel('387020','数据映射导入结果')}
      onCancel={()=> authenticationCenterStore.setState({appEditFormDetailDataMappingImportResultDialogVisible: false})}
      visible={status.appEditFormDetailDataMappingImportResultDialogVisible}
      style={{width: 700, height: 600}}
      hasScroll
      moduleName="integration"
      buttons={[
        <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@zysnev@integrationauthImportResultSaveBtn`} type="primary" onClick={()=> this.onRightMenuClick('BTN_SAVE')}>{getLabel( 309 ,'关闭')}</Button>
      ]}
      moreBtn={[]}
    >
      <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@lgdqq5`}
        datas={this.getRightMenu()}
        collectParams={[]}
      >
        <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@w4exf2`} center={false}  col={1}  needTigger={true} title={getLabel('82341','导入结果')} showGroup={true} items={[]}>
          <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@9exrfw`} 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 {authenticationCenterStore} = this.props;
    if(type == 'BTN_SAVE'){
      //关闭
      authenticationCenterStore.setState({appEditFormDetailDataMappingImportResultDialogVisible: false});
    }

  }

}
