import React from 'react'
import { connect } from 'dva'
import { Tabs } from 'antd'
import ListTablePageBase from './ListTablePageBase'
import TableComponent from "../../baseComponents/TableComponent"

const TabPane = Tabs.TabPane
class ListTablePage extends TableComponent {
  constructor (props) {
    super(props)
    this.state = {
      formData: {},
      tableList: [],
    }
  };

  onAfterGetTablesByFormCode () {

  }

  onRenderTableByList ({ tableList, parentRecord, onRegLoadDataFunc, onLoadParam, onClickRow, isQuery, parentId, onRowSelectChange, rowSelectedKeys }) {
    if (tableList && tableList.length) {
      if (tableList.length === 1) {
        return tableList.map(item => (
          <ListTablePageBase
            key={item.ID}
            tableId={item.ID}
            formId={this.state.formData.ID}
            formData={this.state.formData}
            formCode={this.state.formData ? this.state.formData.CODE : ''}
            onRegLoadDataFunc={onRegLoadDataFunc}
            onLoadParam={onLoadParam}
            parentRecord={parentRecord}
            parentId={parentId}
            onClickRow={onClickRow}
            isQuery={isQuery}
            data={this.props.data}
            customParams={this.props.customParams}
            onRowSelectChange={onRowSelectChange}
            rowSelectedKeys={rowSelectedKeys}
          />
        ))
      }
      else {
        return <Tabs animated={false} defaultActiveKey={tableList[0].ID}>
          {

            tableList.map((item, key) => {
              return <TabPane tab={item.LABEL_NAME} key={item.ID}>
                <ListTablePageBase
                  key={item.ID}
                  tableId={item.ID}
                  formId={this.state.formData.ID}
                  formData={this.state.formData}
                  formCode={this.state.formData ? this.state.formData.CODE : ''}
                  onRegLoadDataFunc={onRegLoadDataFunc}
                  onLoadParam={onLoadParam}
                  parentRecord={parentRecord}
                  parentId={parentId}
                  onClickRow={onClickRow}
                  isQuery={isQuery}
                  data={this.props.data}
                  customParams={this.props.customParams}
                  onRowSelectChange={onRowSelectChange}
                  rowSelectedKeys={rowSelectedKeys}
                />
              </TabPane>
            })

          }
        </Tabs>
      }
    }
    return null
  }
}
export default connect(({ app, loading, listPage, login, search }) => ({ app, loading, listPage, login, search }))(ListTablePage)
