import _Reflect$construct from "@babel/runtime-corejs3/core-js-stable/reflect/construct";
import _extends from "@babel/runtime-corejs3/helpers/extends";
import _readOnlyError from "@babel/runtime-corejs3/helpers/readOnlyError";
import _classCallCheck from "@babel/runtime-corejs3/helpers/classCallCheck";
import _createClass from "@babel/runtime-corejs3/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime-corejs3/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime-corejs3/helpers/getPrototypeOf";
import _inherits from "@babel/runtime-corejs3/helpers/inherits";
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
var __rest = this && this.__rest || function (s, e) {
  var t = {};
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  if (s != null && typeof _Object$getOwnPropertySymbols === "function") for (var i = 0, p = _Object$getOwnPropertySymbols(s); i < p.length; i++) {
    if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  }
  return t;
};
import React from 'react';
import { noop } from 'rxjs';
import { Table } from '../../base';
import { ROW_KEY } from '../cross-table';
import buildCrossTreeTable from './buildCrossTreeTable';
var CrossTreeTable = /*#__PURE__*/function (_React$Component) {
  function CrossTreeTable(props) {
    var _this;
    _classCallCheck(this, CrossTreeTable);
    _this = _callSuper(this, CrossTreeTable, [props]);
    _this.onChangeOpenKeys = function (nextOpenKeys) {
      _this.props.onChangeOpenKeys(nextOpenKeys);
      if (!('openKeys' in _this.props)) {
        _this.setState({
          openKeys: nextOpenKeys
        });
      }
    };
    _this.state = {
      openKeys: props.defaultOpenKeys
    };
    return _this;
  }
  _inherits(CrossTreeTable, _React$Component);
  return _createClass(CrossTreeTable, [{
    key: "render",
    value: function render() {
      var _a = this.props,
        _a$BaseTableComponent = _a.BaseTableComponent,
        BaseTableComponent = _a$BaseTableComponent === void 0 ? Table : _a$BaseTableComponent,
        leftTree = _a.leftTree,
        topTree = _a.topTree,
        getValue = _a.getValue,
        getCellProps = _a.getCellProps,
        primaryColumn = _a.primaryColumn,
        render = _a.render,
        openKeysProp = _a.openKeys,
        defaultOpenKeys = _a.defaultOpenKeys,
        onChangeOpenKeys = _a.onChangeOpenKeys,
        indentSize = _a.indentSize,
        isLeafNode = _a.isLeafNode,
        baseTableRef = _a.baseTableRef,
        others = __rest(_a, ["BaseTableComponent", "leftTree", "topTree", "getValue", "getCellProps", "primaryColumn", "render", "openKeys", "defaultOpenKeys", "onChangeOpenKeys", "indentSize", "isLeafNode", "baseTableRef"]);
      var openKeys = openKeysProp !== null && openKeysProp !== void 0 ? openKeysProp : this.state.openKeys;
      var _buildCrossTreeTable = buildCrossTreeTable({
          leftTree: leftTree,
          topTree: topTree,
          getValue: getValue,
          getCellProps: getCellProps,
          render: render,
          primaryColumn: primaryColumn,
          openKeys: openKeys,
          onChangeOpenKeys: this.onChangeOpenKeys,
          indentSize: indentSize,
          isLeafNode: isLeafNode
        }),
        dataSource = _buildCrossTreeTable.dataSource,
        columns = _buildCrossTreeTable.columns;
      return /*#__PURE__*/React.createElement(BaseTableComponent, _extends({
        ref: baseTableRef
      }, others, {
        primaryKey: ROW_KEY,
        dataSource: dataSource,
        columns: columns
      }));
    }
  }], [{
    key: "getDerivedStateFromProps",
    value: function getDerivedStateFromProps(nextProps) {
      if ('openKeys' in nextProps) {
        return {
          openKeys: nextProps.openKeys
        };
      }
      return null;
    }
  }]);
}(React.Component);
export { CrossTreeTable as default };
CrossTreeTable.defaultProps = {
  defaultOpenKeys: [],
  onChangeOpenKeys: noop
};