/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, h, createVNode, mergeProps } from 'vue';
import isString from 'lodash/isString';
import isFunction from 'lodash/isFunction';
import get from 'lodash/get';
import { useTNodeJSX } from '../hooks/tnode.js';
import { formatRowAttributes, formatRowClassNames } from './utils.js';
import { getColumnFixedStyles } from './hooks/useFixed.js';
import useRowspanAndColspan, { getCellKey } from './hooks/useRowspanAndColspan.js';
import useClassName from './hooks/useClassName.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import '@babel/runtime/helpers/typeof';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/debounce';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../_common/js/utils/getScrollbarWidth.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../utils/dom.js';
import '../_chunks/dep-2e5d8948.js';
import '../utils/easing.js';
import '../hooks/useConfig.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import 'dayjs';
import '../_chunks/dep-4580aabe.js';
import '../config-provider/type.js';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var TFoot = defineComponent({
  name: "TFoot",
  props: {
    rowKey: String,
    isFixedHeader: Boolean,
    rowAndColFixedPosition: Map,
    footData: Array,
    columns: Array,
    rowAttributes: [Array, Object, Function],
    rowClassName: [Array, String, Object, Function],
    thWidthList: [Object],
    footerSummary: [String, Function],
    rowspanAndColspanInFooter: Function
  },
  setup: function setup(props, context) {
    var renderTNode = useTNodeJSX();
    var classnames = useClassName();
    var _toRefs = toRefs(props),
      footData = _toRefs.footData,
      columns = _toRefs.columns,
      rowKey = _toRefs.rowKey,
      rowspanAndColspanInFooter = _toRefs.rowspanAndColspanInFooter;
    var _useRowspanAndColspan = useRowspanAndColspan(footData, columns, rowKey, rowspanAndColspanInFooter),
      skipSpansMap = _useRowspanAndColspan.skipSpansMap;
    var renderTFootCell = function renderTFootCell(p) {
      var col = p.col,
        row = p.row;
      if (isFunction(col.foot)) return col.foot(h, p);
      if (isString(col.foot) && context.slots[col.foot]) return context.slots[col.foot](p) || col.foot;
      return col.foot || get(row, col.colKey);
    };
    return _objectSpread(_objectSpread({
      skipSpansMap: skipSpansMap
    }, classnames), {}, {
      renderTFootCell: renderTFootCell,
      renderTNode: renderTNode
    });
  },
  render: function render() {
    var _this$footData,
      _this = this;
    if (!this.columns) return null;
    var theadClasses = [this.tableFooterClasses.footer, _defineProperty({}, this.tableFooterClasses.fixed, this.isFixedHeader)];
    var footerDomList = (_this$footData = this.footData) === null || _this$footData === void 0 ? void 0 : _this$footData.map(function (row, rowIndex) {
      var trAttributes = formatRowAttributes(_this.rowAttributes, {
        row: row,
        rowIndex: rowIndex,
        type: "foot"
      });
      var customClasses = formatRowClassNames(_this.rowClassName, {
        row: row,
        rowIndex: rowIndex,
        type: "foot"
      }, _this.rowKey || "id");
      return createVNode("tr", mergeProps(trAttributes, {
        "key": rowIndex,
        "class": customClasses
      }), [_this.columns.map(function (col, colIndex) {
        var _this$thWidthList;
        var cellSpans = {};
        var spanState = null;
        if (_this.skipSpansMap.size) {
          var _spanState, _spanState2;
          var cellKey = getCellKey(row, _this.rowKey, col.colKey, colIndex);
          spanState = _this.skipSpansMap.get(cellKey) || {};
          ((_spanState = spanState) === null || _spanState === void 0 ? void 0 : _spanState.rowspan) > 1 && (cellSpans.rowspan = spanState.rowspan);
          ((_spanState2 = spanState) === null || _spanState2 === void 0 ? void 0 : _spanState2.colspan) > 1 && (cellSpans.colspan = spanState.colspan);
          if (spanState.skipped) return null;
        }
        var tdStyles = getColumnFixedStyles(col, colIndex, _this.rowAndColFixedPosition, _this.tableColFixedClasses);
        var style = _objectSpread({}, tdStyles.style);
        if ((_this$thWidthList = _this.thWidthList) !== null && _this$thWidthList !== void 0 && _this$thWidthList[col.colKey]) style.width = "".concat(_this.thWidthList[col.colKey], "px");
        return createVNode("td", mergeProps(_objectSpread({
          key: col.colKey
        }, cellSpans), {
          "class": tdStyles.classes,
          "style": style
        }), [_this.renderTFootCell({
          row: row,
          rowIndex: rowIndex,
          col: col,
          colIndex: colIndex
        })]);
      })]);
    });
    var footerSummary = this.renderTNode("footerSummary");
    if (!footerSummary && (!this.footData || !this.footData.length)) return null;
    return createVNode("tfoot", {
      "ref": "tFooterRef",
      "class": theadClasses
    }, [footerSummary && createVNode("tr", {
      "class": this.tableFullRowClasses.base
    }, [createVNode("td", {
      "colspan": this.columns.length
    }, [createVNode("div", {
      "class": this.tableFullRowClasses.innerFullElement
    }, [footerSummary])])]), footerDomList]);
  }
});

export { TFoot as default };
//# sourceMappingURL=tfoot.js.map
