"use strict";

var _Reflect$construct = require("@babel/runtime-corejs3/core-js-stable/reflect/construct");

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/getPrototypeOf"));

var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));

var _react = _interopRequireDefault(require("react"));

var _rxjs = require("rxjs");

var _base = require("../../base");

var _crossTable = require("../cross-table");

var _buildCrossTreeTable2 = _interopRequireDefault(require("./buildCrossTreeTable"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var __rest = void 0 && (void 0).__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 _getOwnPropertySymbols.default === "function") for (var i = 0, p = (0, _getOwnPropertySymbols.default)(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;
};

var CrossTreeTable = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2.default)(CrossTreeTable, _React$Component);

  var _super = _createSuper(CrossTreeTable);

  function CrossTreeTable(props) {
    var _this;

    (0, _classCallCheck2.default)(this, CrossTreeTable);
    _this = _super.call(this, 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;
  }

  (0, _createClass2.default)(CrossTreeTable, [{
    key: "render",
    value: function render() {
      var _a = this.props,
          _a$BaseTableComponent = _a.BaseTableComponent,
          BaseTableComponent = _a$BaseTableComponent === void 0 ? _base.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 = (0, _buildCrossTreeTable2.default)({
        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.default.createElement(BaseTableComponent, (0, _extends2.default)({
        ref: baseTableRef
      }, others, {
        primaryKey: _crossTable.ROW_KEY,
        dataSource: dataSource,
        columns: columns
      }));
    }
  }], [{
    key: "getDerivedStateFromProps",
    value: function getDerivedStateFromProps(nextProps) {
      if ('openKeys' in nextProps) {
        return {
          openKeys: nextProps.openKeys
        };
      }

      return null;
    }
  }]);
  return CrossTreeTable;
}(_react.default.Component);

exports.default = CrossTreeTable;
CrossTreeTable.defaultProps = {
  defaultOpenKeys: [],
  onChangeOpenKeys: _rxjs.noop
};