import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React, { Component } from 'react';
import { connect } from '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) {
  _inherits(TableFooterRow, _Component);

  var _super = _createSuper(TableFooterRow);

  function TableFooterRow() {
    var _this;

    _classCallCheck(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));

    _defineProperty(_assertThisInitialized(_this), "handleMouseEnter", function () {
      var onHover = _this.props.onHover;

      if (onHover) {
        onHover(true, FOOTER_ROW_KEY);
      }
    });

    _defineProperty(_assertThisInitialized(_this), "handleMouseLeave", function () {
      var onHover = _this.props.onHover;

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

    return _this;
  }

  _createClass(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.createElement(FooterRow, {
        onMouseEnter: this.handleMouseEnter,
        onMouseLeave: this.handleMouseLeave,
        className: className,
        style: {
          height: height
        }
      }, columns.map(function (col) {
        return /*#__PURE__*/React.createElement(FooterCell, {
          key: col.key || col.dataIndex
        }, col.footer ? getColumnFooter(col)(data) : null);
      }));
    }
  }]);

  return TableFooterRow;
}(Component);

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

export default connect(function (state, props) {
  return {
    hovered: state.currentHoverKey === FOOTER_ROW_KEY,
    height: getRowHeight(state, props)
  };
})(TableFooterRow);
//# sourceMappingURL=TableFooterRow.js.map
