import { inject, observer } from "mobx-react";
import React, { Component } from "react";
import { WeaTableEdit } from "ecCom";
import * as mobx from "mobx";

const toJS = mobx.toJS;

@inject("columnSetting")
@observer
export default class DefineShowItems extends Component {
  constructor(props) {
    super(props);
  }

  componentDidMount() {
    this.init();
  }

  init = () => {
    const { columnSetting } = this.props;
    columnSetting.loadTabTwoRelatedData();
  };

  onRowSelect = (sRowKeys, rows, dataIndex, selectedDatas) => {
    const { columnSetting } = this.props;
    if (dataIndex === undefined || selectedDatas === undefined) {
      return;
    }
    columnSetting.setEnableRows(selectedDatas.isused);
  };

  render() {
    const { columnSetting } = this.props, { tabTwoRelatedData } = columnSetting;
    const { datas, columns, selectedData, loading } = tabTwoRelatedData;
    return (
      <WeaTableEdit
        ecId={`${this && this.props && this.props.ecId || ""}_WeaTableEdit@7rorir`}
        draggable
        deleteConfirm
        title=""
        columns={toJS(columns)}
        datas={toJS(datas)}
        copyFilterProps={["id"]}
        selectedData={!loading && toJS(selectedData)}
        onChange={e => columnSetting.setTableEditDatas(e)}
        onRowSelect={(sRowKeys, rows, dataIndex, selectedDatas) => this.onRowSelect(sRowKeys, rows, dataIndex, selectedDatas)}
      />
    );
  }
}
