/*
 * Author: 黎永顺
 * name: 分组设置-定量-组距式分组编辑表格
 * Description:
 * Date: 2023/4/12
 */
import React, { Component } from "react";
import { WeaLocaleProvider, WeaTableEdit } from "ecCom";

const { getLabel } = WeaLocaleProvider;

class GroupSpacingEditTable extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dataSource: []
    };
  }

  componentDidMount() {
    const { setting4RationGroupSpacing } = this.props;
    this.setState({
      dataSource: _.map(setting4RationGroupSpacing, item => {
        return {
          ...item,
          includeStart: item.includeStart ? "1" : "0",
          includeEnd: item.includeEnd ? "1" : "0"
        };
      })
    });
  }

  handleChangeTableData = (dataSource) => {
    const { onChange } = this.props;
    this.setState({ dataSource }, () => onChange(this.state.dataSource));
  };

  render() {
    const { dataSource } = this.state;
    const columns = [
      {
        title: getLabel(111, "起始值"),
        dataIndex: "startValue",
        key: "startValue",
        com: [
          { label: "", key: "startValue", type: "INPUTNUMBER" }
        ]
      },
      {
        title: getLabel(111, "含"),
        dataIndex: "includeStart",
        key: "includeStart",
        com: [
          {
            type: "CHECKBOX",
            key: "includeStart",
            otherParams: { content: getLabel(111, "含") }
          }
        ]
      },
      {
        title: getLabel(111, "至"),
        dataIndex: "to",
        key: "to",
        com: [
          { label: "", type: "TEXT" }
        ]
      },
      {
        title: getLabel(111, "结束值"),
        dataIndex: "endValue",
        key: "endValue",
        com: [
          { label: "", key: "endValue", type: "INPUTNUMBER" }
        ]
      },
      {
        title: getLabel(111, "含"),
        dataIndex: "includeEnd",
        key: "includeEnd",
        com: [
          {
            type: "CHECKBOX",
            key: "includeEnd",
            otherParams: { content: getLabel(111, "含") }
          }
        ]
      }
    ];
    return (
      <WeaTableEdit
        draggable={true} deleteConfirm columns={columns}
        datas={_.map(dataSource, item => ({ ...item, to: getLabel(111, "至") }))}
        showCopy={false} onChange={this.handleChangeTableData}
      />
    );
  }
}

export default GroupSpacingEditTable;
