import React from "react";
import assign from "lodash/assign";
import deepcopy from 'lodash/cloneDeep';
import WebCustomColumnDrawer from "../component/webCustomColumnDrawer";
import filterColumn from "../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: deepcopy(columns),
      currentColumns: filterColumn(columns)
    };
    this.state = this.state || {};
    assign(this.state, mergeState);
  },
  showCustomColumnDrawer: function showCustomColumnDrawer() {
    this.setState({
      isCustomColumnDrawerShown: true
    });
  },
  hideCustomColumnDrawer: function hideCustomColumnDrawer() {
    this.setState({
      isCustomColumnDrawerShown: false
    });
  },
  setOriginalColumns: function setOriginalColumns(columns) {
    this.setState({
      originalColumns: deepcopy(columns)
    });
  },
  changeCurrentColumns: function changeCurrentColumns(columns) {
    this.setState({
      currentColumns: filterColumn(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.createElement(WebCustomColumnDrawer, {
      locale: locale,
      columns: originalColumns,
      nextTablePrefix: nextTablePrefix,
      visible: isCustomColumnDrawerShown,
      onClose: this.hideCustomColumnDrawer.bind(this),
      onOk: function onOk(columns) {
        _this.changeCurrentColumns(columns);
        onColumnsChange(columns);
        _this.hideCustomColumnDrawer();
      }
    });
  }
};
export default methods;