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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var helper = require('../../../chunks/helper.js');
var VueCompositionAPI = require('@vue/composition-api');
var isString = require('lodash/isString');
var isFunction = require('lodash/isFunction');
var get = require('lodash/get');
var hooks_lnode = require('../../../hooks/lnode.js');
var components_table_utils = require('../utils.js');
var components_table_hooks_useFixed = require('../hooks/useFixed.js');
var components_table_hooks_useRowspanAndColspan = require('../hooks/useRowspanAndColspan.js');
var components_table_hooks_useClassName = require('../hooks/useClassName.js');
require('lodash/isEmpty');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../../hooks/render-lnode.js');
require('lodash');
require('lodash/isObject');
require('lodash/debounce');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../chunks/helper2.js');
require('../../../utils/dom.js');
require('vue');
require('raf');
require('../../../utils/easing.js');
require('../../config-provider/useConfig.js');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);

var TFoot = VueCompositionAPI.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 = hooks_lnode.useLNodeJSX();
    const classnames = components_table_hooks_useClassName["default"]();
    const {
      footData,
      columns,
      rowKey,
      rowspanAndColspanInFooter
    } = VueCompositionAPI.toRefs(props);
    const {
      skipSpansMap
    } = components_table_hooks_useRowspanAndColspan["default"](footData, columns, rowKey, rowspanAndColspanInFooter);
    const renderTFootCell = p => {
      const {
        col,
        row
      } = p;
      if (isFunction__default["default"](col.foot)) return col.foot(VueCompositionAPI.h, p);
      if (isString__default["default"](col.foot) && context.slots[col.foot]) return context.slots[col.foot](p);
      return col.foot || get__default["default"](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 = components_table_utils.formatRowAttributes(this.rowAttributes, {
        row,
        rowIndex,
        type: "foot"
      });
      const customClasses = components_table_utils.formatRowClassNames(this.rowClassName, {
        row,
        rowIndex,
        type: "foot"
      }, this.rowKey || "id");
      return h("tr", helper.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 = components_table_hooks_useRowspanAndColspan.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 = components_table_hooks_useFixed.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.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]);
  }
});

exports["default"] = TFoot;
//# sourceMappingURL=tfoot.js.map
