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

@inject("columnSetting")
@observer
class CustomItem extends Component {
  componentDidMount() {
    this.init();
  }

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

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

  render() {
    const { columnSetting } = this.props, { tabThreeRelatedData } = columnSetting;
    const { datas, columns, selectedData, loading } = tabThreeRelatedData;
    return (
      <div>
        <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.setCustomTableEditDatas(e)}
          onRowSelect={(sRowKeys, rows, dataIndex, selectedDatas) => this.onRowSelect(sRowKeys, rows, dataIndex, selectedDatas)}
        />
      </div>
    );
  }
}

export default CustomItem;
