/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { h as helper } from '../../../chunks/helper.js';
import { defineComponent, toRefs, h } from '@vue/composition-api';
import isString from 'lodash/isString';
import isFunction from 'lodash/isFunction';
import get from 'lodash/get';
import { useLNodeJSX } from '../../../hooks/lnode.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 '../../../chunks/_commonjsHelpers.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../../hooks/render-lnode.js';
import 'lodash';
import 'lodash/isObject';
import 'lodash/debounce';
import '../../../chunks/index.js';
import '../../../chunks/log.js';
import '../../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../../chunks/helper2.js';
import '../../../chunks/defineProperty-838e4192.js';
import '../../../utils/dom.js';
import 'vue';
import 'raf';
import '../../../utils/easing.js';
import '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';

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(props, context) {
    const renderLNode = useLNodeJSX();
    const classnames = useClassName();
    const {
      footData,
      columns,
      rowKey,
      rowspanAndColspanInFooter
    } = toRefs(props);
    const {
      skipSpansMap
    } = useRowspanAndColspan(footData, columns, rowKey, rowspanAndColspanInFooter);
    const renderTFootCell = p => {
      const {
        col,
        row
      } = p;
      if (isFunction(col.foot)) return col.foot(h, p);
      if (isString(col.foot) && context.slots[col.foot]) return context.slots[col.foot](p);
      return col.foot || get(row, col.colKey);
    };
    return {
      skipSpansMap,
      ...classnames,
      renderTFootCell,
      renderLNode
    };
  },
  render() {
    var _this$footData;
    const h = arguments[0];
    if (!this.columns) return null;
    const theadClasses = [this.tableFooterClasses.footer, {
      [this.tableFooterClasses.fixed]: this.isFixedHeader
    }];
    const footerDomList = (_this$footData = this.footData) === null || _this$footData === void 0 ? void 0 : _this$footData.map((row, rowIndex) => {
      const trAttributes = formatRowAttributes(this.rowAttributes, {
        row,
        rowIndex,
        type: "foot"
      });
      const customClasses = formatRowClassNames(this.rowClassName, {
        row,
        rowIndex,
        type: "foot"
      }, this.rowKey || "id");
      return h("tr", helper([{
        "key": rowIndex
      }, {
        "attrs": trAttributes
      }, {
        "class": customClasses
      }]), [this.columns.map((col, colIndex) => {
        var _this$thWidthList;
        const cellSpans = {};
        let spanState = null;
        if (this.skipSpansMap.size) {
          var _spanState, _spanState2;
          const 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;
        }
        const tdStyles = getColumnFixedStyles(col, colIndex, this.rowAndColFixedPosition, this.tableColFixedClasses);
        const style = {
          ...tdStyles.style
        };
        if ((_this$thWidthList = this.thWidthList) !== null && _this$thWidthList !== void 0 && _this$thWidthList[col.colKey]) style.width = `${this.thWidthList[col.colKey]}px`;
        return h("td", helper([{}, {
          "attrs": {
            key: col.colKey,
            ...cellSpans
          }
        }, {
          "class": tdStyles.classes,
          "style": style
        }]), [this.renderTFootCell({
          row,
          rowIndex,
          col,
          colIndex
        })]);
      })]);
    });
    const footerSummary = this.renderLNode("footerSummary");
    if (!footerSummary && (!this.footData || !this.footData.length)) return null;
    return h("tfoot", {
      "ref": "tFooterRef",
      "class": theadClasses
    }, [footerSummary && h("tr", {
      "class": this.tableFullRowClasses.base
    }, [h("td", {
      "attrs": {
        "colspan": this.columns.length
      }
    }, [h("div", {
      "class": this.tableFullRowClasses.innerFullElement
    }, [footerSummary])])]), footerDomList]);
  }
});

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