"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _assign = _interopRequireDefault(require("lodash/assign"));
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
var _webCustomColumnDrawer = _interopRequireDefault(require("../component/webCustomColumnDrawer"));
var _filterColumn = _interopRequireDefault(require("../utils/filterColumn"));
var methods = {
  init: function init() {
    var _this$props$columns = this.props.columns,
      columns = _this$props$columns === void 0 ? [] : _this$props$columns;
    var mergeState = {
      isCustomColumnDrawerShown: false,
      originalColumns: (0, _cloneDeep["default"])(columns),
      currentColumns: (0, _filterColumn["default"])(columns)
    };
    this.state = this.state || {};
    (0, _assign["default"])(this.state, mergeState);
  },
  showCustomColumnDrawer: function showCustomColumnDrawer() {
    this.setState({
      isCustomColumnDrawerShown: true
    });
  },
  hideCustomColumnDrawer: function hideCustomColumnDrawer() {
    this.setState({
      isCustomColumnDrawerShown: false
    });
  },
  setOriginalColumns: function setOriginalColumns(columns) {
    this.setState({
      originalColumns: (0, _cloneDeep["default"])(columns)
    });
  },
  changeCurrentColumns: function changeCurrentColumns(columns) {
    this.setState({
      currentColumns: (0, _filterColumn["default"])(columns)
    });
  },
  renderCustomColumnDrawer: function renderCustomColumnDrawer() {
    var _this = this;
    var _this$state = this.state,
      isCustomColumnDrawerShown = _this$state.isCustomColumnDrawerShown,
      originalColumns = _this$state.originalColumns;
    var _this$props = this.props,
      nextTablePrefix = _this$props.nextTablePrefix,
      locale = _this$props.locale,
      _this$props$onColumns = _this$props.onColumnsChange,
      onColumnsChange = _this$props$onColumns === void 0 ? function () {} : _this$props$onColumns;
    return /*#__PURE__*/_react["default"].createElement(_webCustomColumnDrawer["default"], {
      locale: locale,
      columns: originalColumns,
      nextTablePrefix: nextTablePrefix,
      visible: isCustomColumnDrawerShown,
      onClose: this.hideCustomColumnDrawer.bind(this),
      onOk: function onOk(columns) {
        _this.changeCurrentColumns(columns);
        onColumnsChange(columns);
        _this.hideCustomColumnDrawer();
      }
    });
  }
};
var _default = methods;
exports["default"] = _default;