import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import React, { Component } from 'react';
import Checkbox from '../checkbox';
import InputNumber from '../input-number';
import { getColumnKey } from './util';
var sortInputStyle = {
  width: '60px'
};

var sortInputWrapStyle = _objectSpread(_objectSpread({}, sortInputStyle), {}, {
  display: 'inline-block'
});

var sortInputWrapStyleCenter = _objectSpread(_objectSpread({}, sortInputWrapStyle), {}, {
  textAlign: 'center'
});

var ColumnFilterMenuItem = /*#__PURE__*/function (_Component) {
  _inherits(ColumnFilterMenuItem, _Component);

  var _super = _createSuper(ColumnFilterMenuItem);

  function ColumnFilterMenuItem(props) {
    var _this;

    _classCallCheck(this, ColumnFilterMenuItem);

    _this = _super.call(this, props); // 修改是否 lock (fixedLeft)

    _this.handleFixedLeftChange = function (e) {
      var customColumn = _this.state.customColumn;
      var fixedLeft = e.target.checked ? 1 : 0;

      _this.setState({
        customColumn: _objectSpread(_objectSpread({}, customColumn), {}, {
          fixedLeft: fixedLeft,
          fixedRight: fixedLeft === 1 ? 0 : customColumn.fixedRight
        })
      });
    }; // 修改是否隐藏


    _this.handleHiddenChange = function (e) {
      var customColumn = _this.state.customColumn;
      var hidden = e.target.checked ? 0 : 1;

      _this.setState({
        customColumn: _objectSpread(_objectSpread({}, customColumn), {}, {
          hidden: hidden
        })
      });
    }; // 修改排序


    _this.handleOrderSeqChange = function (value) {
      var customColumn = _this.state.customColumn;

      _this.setState({
        customColumn: _objectSpread(_objectSpread({}, customColumn), {}, {
          orderSeq: value
        })
      });
    }; // 获取校验的数据


    _this.getValidateCustomColumn = function () {
      var customColumn = _this.state.customColumn;
      return Promise.resolve(customColumn);
    };

    var customColumn = props.customColumn || {
      hidden: 0,
      fixedLeft: 0,
      fixedRight: 0,
      orderSeq: props.index,
      fieldKey: getColumnKey(props.column, props.index)
    };
    _this.state = {
      customColumn: customColumn,
      prevCustomColumn: customColumn
    };
    return _this;
  }

  _createClass(ColumnFilterMenuItem, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          column = _this$props.column,
          checkboxPrefixCls = _this$props.checkboxPrefixCls,
          inputNumberProps = _this$props.inputNumberProps;
      var customColumn = this.state.customColumn;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
        style: sortInputWrapStyleCenter
      }, /*#__PURE__*/React.createElement(Checkbox, {
        prefixCls: checkboxPrefixCls,
        style: sortInputStyle,
        checked: customColumn.hidden !== 1,
        onChange: this.handleHiddenChange
      })), /*#__PURE__*/React.createElement("div", {
        className: "dropdown-menu-text"
      }, column.title), /*#__PURE__*/React.createElement("div", {
        style: sortInputWrapStyleCenter
      }, /*#__PURE__*/React.createElement(Checkbox, {
        prefixCls: checkboxPrefixCls,
        name: "fixedLeft",
        checked: customColumn.fixedLeft === 1,
        onChange: this.handleFixedLeftChange
      })), /*#__PURE__*/React.createElement("div", {
        style: sortInputWrapStyle
      }, /*#__PURE__*/React.createElement(InputNumber, _extends({}, inputNumberProps, {
        name: "orderSeq",
        style: sortInputStyle,
        min: 0,
        step: 1,
        precision: 0,
        value: customColumn.orderSeq,
        onChange: this.handleOrderSeqChange
      }))));
    }
  }], [{
    key: "getDerivedStateFromProps",
    value: function getDerivedStateFromProps(nextProps, prevState) {
      var customColumn = nextProps.customColumn;
      var prevCustomColumn = prevState.prevCustomColumn;

      if (customColumn && prevCustomColumn !== customColumn) {
        return {
          customColumn: customColumn,
          prevCustomColumn: customColumn
        };
      }

      return null;
    }
  }]);

  return ColumnFilterMenuItem;
}(Component);

export default ColumnFilterMenuItem;
//# sourceMappingURL=ColumnFilterMenuItem.js.map
