"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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

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

var _mobxReactLite = require("mobx-react-lite");

var _mobx = require("mobx");

var _classnames = _interopRequireDefault(require("classnames"));

var _measureScrollbar = _interopRequireDefault(require("../../../lib/_util/measureScrollbar"));

var _UnitConvertor = require("../../../lib/_util/UnitConvertor");

var _TableContext = _interopRequireDefault(require("./TableContext"));

var _enum = require("./enum");

var _TableFooterCell = _interopRequireDefault(require("./TableFooterCell"));

var _utils = require("./utils");

var _ResizeObservedRow = _interopRequireDefault(require("./ResizeObservedRow"));

var _TableStore = require("./TableStore");

var TableFooter = function TableFooter(props) {
  var lock = props.lock,
      columnGroups = props.columnGroups;

  var _useContext = (0, _react.useContext)(_TableContext["default"]),
      prefixCls = _useContext.prefixCls,
      rowHeight = _useContext.rowHeight,
      tableStore = _useContext.tableStore,
      fullColumnWidth = _useContext.fullColumnWidth;

  var overflowX = tableStore.overflowX;
  var handleResize = (0, _react.useCallback)((0, _mobx.action)(function (index, height) {
    (0, _mobx.set)(tableStore.lockColumnsFootRowsHeight, index, height);
  }), [tableStore]);

  var getTds = function getTds() {
    var customizable = tableStore.customizable,
        rowDraggable = tableStore.rowDraggable,
        dragColumnAlign = tableStore.dragColumnAlign;
    var hasPlaceholder = lock !== _enum.ColumnLock.left && tableStore.overflowY;
    var right = hasPlaceholder ? (0, _measureScrollbar["default"])() : 0;
    var tds = columnGroups.leafs.map(function (columnGroup, index, cols) {
      var key = columnGroup.key;

      if (key !== _TableStore.CUSTOMIZED_KEY) {
        var colSpan = customizable && lock !== _enum.ColumnLock.left && (!rowDraggable || dragColumnAlign !== _enum.DragColumnAlign.right) && index === cols.length - 2 ? 2 : 1;
        var cellProps = {};

        if (colSpan > 1) {
          cellProps.colSpan = colSpan;
        }

        return /*#__PURE__*/_react["default"].createElement(_TableFooterCell["default"], (0, _extends2["default"])({
          key: key,
          columnGroup: columnGroup,
          right: right
        }, cellProps));
      }

      return undefined;
    });
    var useEmptyColumn = !fullColumnWidth && lock !== _enum.ColumnLock.left && !tableStore.overflowX && !tableStore.hasEmptyWidthColumn;

    if (useEmptyColumn) {
      tds.push( /*#__PURE__*/_react["default"].createElement("th", {
        key: "empty-column",
        className: "".concat(prefixCls, "-cell"),
        style: {
          lineHeight: 1
        }
      }));
    }

    if (hasPlaceholder) {
      var placeHolderProps = {
        key: 'fixed-column',
        style: {
          lineHeight: 1
        }
      };
      var classList = ["".concat(prefixCls, "-cell")];

      if ((0, _utils.isStickySupport)() && overflowX) {
        placeHolderProps.style = {
          right: 0
        };
        classList.push("".concat(prefixCls, "-cell-fix-right"));
      }

      placeHolderProps.className = classList.join(' ');
      tds.push( /*#__PURE__*/_react["default"].createElement("th", (0, _extends2["default"])({}, placeHolderProps), "\xA0"));
    }

    return tds;
  };

  var style = !(0, _utils.isStickySupport)() && lock && (rowHeight === 'auto' || tableStore.autoFootHeight) ? {
    height: (0, _UnitConvertor.pxToRem)((0, _mobx.get)(tableStore.lockColumnsFootRowsHeight, 0), true)
  } : undefined;

  var tr = /*#__PURE__*/_react["default"].createElement("tr", {
    style: style
  }, getTds());

  var classString = (0, _classnames["default"])("".concat(prefixCls, "-tfoot"), (0, _defineProperty2["default"])({}, "".concat(prefixCls, "-tfoot-bordered"), overflowX));
  return /*#__PURE__*/_react["default"].createElement("tfoot", {
    className: classString
  }, !(0, _utils.isStickySupport)() && !lock && (rowHeight === 'auto' || tableStore.autoFootHeight) ? /*#__PURE__*/_react["default"].createElement(_ResizeObservedRow["default"], {
    onResize: handleResize,
    rowIndex: 0
  }, tr) : tr);
};

TableFooter.displayName = 'TableFooter';

var _default = (0, _mobxReactLite.observer)(TableFooter);

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