"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

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

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

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

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

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

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

var _miniStore = require("mini-store");

var FOOTER_ROW_KEY = "rc_table_footer_key_".concat(Date.now());

function getColumnFooter(col) {
  if (typeof col.footer === 'function') return col.footer;
  return function () {
    return col.footer;
  };
}

var TableFooterRow = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(TableFooterRow, _Component);

  var _super = (0, _createSuper2["default"])(TableFooterRow);

  function TableFooterRow() {
    var _this;

    (0, _classCallCheck2["default"])(this, TableFooterRow);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMouseEnter", function () {
      var onHover = _this.props.onHover;

      if (onHover) {
        onHover(true, FOOTER_ROW_KEY);
      }
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMouseLeave", function () {
      var onHover = _this.props.onHover;

      if (onHover) {
        onHover(false, FOOTER_ROW_KEY);
      }
    });
    return _this;
  }

  (0, _createClass2["default"])(TableFooterRow, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          columns = _this$props.columns,
          data = _this$props.data,
          components = _this$props.components,
          prefixCls = _this$props.prefixCls,
          hovered = _this$props.hovered,
          height = _this$props.height;
      var FooterRow = components.footer.row;
      var FooterCell = components.footer.cell;
      var className = "".concat(prefixCls, "-footer-row");

      if (hovered) {
        className += " ".concat(prefixCls, "-row-hover");
      }

      return /*#__PURE__*/_react["default"].createElement(FooterRow, {
        onMouseEnter: this.handleMouseEnter,
        onMouseLeave: this.handleMouseLeave,
        className: className,
        style: {
          height: height
        }
      }, columns.map(function (col) {
        return /*#__PURE__*/_react["default"].createElement(FooterCell, {
          key: col.key || col.dataIndex
        }, col.footer ? getColumnFooter(col)(data) : null);
      }));
    }
  }]);
  return TableFooterRow;
}(_react.Component);

function getRowHeight(state, props) {
  var fixedColumnsFootRowsHeight = state.fixedColumnsFootRowsHeight;
  var fixed = props.fixed;
  return fixed ? fixedColumnsFootRowsHeight[0] : null;
}

var _default = (0, _miniStore.connect)(function (state, props) {
  return {
    hovered: state.currentHoverKey === FOOTER_ROW_KEY,
    height: getRowHeight(state, props)
  };
})(TableFooterRow);

exports["default"] = _default;
//# sourceMappingURL=TableFooterRow.js.map
