/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-37d5b9c4.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import camelCase from 'lodash/camelCase';
import get from 'lodash/get';
import pick from 'lodash/pick';
import TrElement, { ROW_LISTENERS, TABLE_PROPS } from './tr.js';
import { useConfig } from '../config-provider/useConfig.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import useClassName from './hooks/useClassName.js';
import baseTableProps from './base-table-props.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/isFunction';
import 'lodash/upperFirst';
import 'lodash/isString';
import './utils.js';
import 'lodash/isObject';
import './hooks/useFixed.js';
import '@babel/runtime/helpers/slicedToArray';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../_common/js/utils/getScrollbarWidth.js';
import '../utils/dom.js';
import 'vue';
import 'raf';
import '../utils/easing.js';
import './ellipsis.js';
import 'lodash/debounce';
import '../utils/render-tnode.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../config.js';
import '../utils/classnames.js';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../_common/js/utils/set-style.js';
import '../popup/props.js';
import '../popup/container.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/css.js';
import '../popup/type.js';
import './hooks/useLazyLoad.js';
import '../_common/js/utils/observe.js';
import 'lodash/cloneDeep';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import 'lodash/isEmpty';
import 'lodash/kebabCase';
import '../hooks/render-tnode.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 ROW_AND_TD_LISTENERS = ROW_LISTENERS.concat("cell-click");
var extendTableProps = ["rowKey", "rowClassName", "rowAttributes", "loading", "empty", "fixedRows", "firstFullRow", "lastFullRow", "rowspanAndColspan", "scroll", "onCellClick", "onPageChange", "onRowClick", "onRowDblclick", "onRowMouseover", "onRowMousedown", "onRowMouseenter", "onRowMouseleave", "onRowMouseup", "onScroll", "onScrollX", "onScrollY"];
var TBody = defineComponent({
  name: "TBody",
  props: _objectSpread({
    data: Array,
    columns: Array,
    rowAndColFixedPosition: Map,
    showColumnShadow: Object,
    tableElm: {},
    tableWidth: Number,
    isWidthOverflow: Boolean,
    translateY: Number,
    scrollType: String,
    isVirtual: Boolean,
    rowHeight: Number,
    trs: Map,
    bufferSize: Number,
    tableContentElm: {},
    handleRowMounted: Function,
    renderExpandedRow: Function,
    firstFullRow: [String, Function],
    lastFullRow: [String, Function]
  }, pick(baseTableProps, extendTableProps)),
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var renderTNode = useTNodeJSX();

    var _useConfig = useConfig("table"),
        t = _useConfig.t,
        global = _useConfig.global;

    var _useClassName = useClassName(),
        tableFullRowClasses = _useClassName.tableFullRowClasses,
        tableBaseClass = _useClassName.tableBaseClass;

    var tbodyClasses = computed(function () {
      return [tableBaseClass.body];
    });
    var isFixedLeftColumn = computed(function () {
      return props.isWidthOverflow && !!props.columns.find(function (col) {
        return col.fixed === "left";
      });
    });

    var getTrListeners = function getTrListeners() {
      var trListeners = {};
      ROW_AND_TD_LISTENERS.forEach(function (eventName) {
        var name = ["cell-click"].includes(eventName) ? eventName : "row-".concat(eventName);

        trListeners[name] = function (context) {
          emit(name, context);
        };
      });
      return trListeners;
    };

    return {
      t: t,
      global: global,
      tableFullRowClasses: tableFullRowClasses,
      tbodyClasses: tbodyClasses,
      tableBaseClass: tableBaseClass,
      isFixedLeftColumn: isFixedLeftColumn,
      renderTNode: renderTNode,
      getTrListeners: getTrListeners
    };
  },
  render: function render(h) {
    var _this = this,
        _this$data,
        _this$data2;

    var renderEmpty = function renderEmpty(h2, columns) {
      return h("tr", {
        "class": [_this.tableBaseClass.emptyRow, _defineProperty({}, _this.tableFullRowClasses.base, _this.isWidthOverflow)]
      }, [h("td", {
        "attrs": {
          "colspan": columns.length
        }
      }, [h("div", {
        "class": [_this.tableBaseClass.empty, _defineProperty({}, _this.tableFullRowClasses.innerFullRow, _this.isWidthOverflow)],
        "style": _this.isWidthOverflow ? {
          width: "".concat(_this.tableWidth, "px")
        } : {}
      }, [_this.renderTNode("empty") || _this.t(_this.global.empty)])])]);
    };

    var getFullRow = function getFullRow(h2, columnLength2, type) {
      var tType = camelCase(type);

      var fullRowNode = _this.renderTNode(tType);

      if (["", null, void 0, false].includes(fullRowNode)) return null;
      var classes = [_this.tableFullRowClasses.base, _this.tableFullRowClasses[tType]];
      return h("tr", {
        "class": classes
      }, [h("td", {
        "attrs": {
          "colspan": columnLength2
        }
      }, [h("div", {
        "class": _defineProperty({}, _this.tableFullRowClasses.innerFullRow, _this.isFixedToLeft),
        "style": _this.isFixedToLeft ? {
          width: "".concat(_this.tableWidth, "px")
        } : {}
      }, [h("div", {
        "class": _this.tableFullRowClasses.innerFullElement
      }, [fullRowNode])])])]);
    };

    var skipSpansMap = /* @__PURE__ */new Map();

    var onTrRowspanOrColspan = function onTrRowspanOrColspan(params, cellSpans) {
      var rowIndex = params.rowIndex,
          colIndex = params.colIndex;
      if (!cellSpans.rowspan && !cellSpans.colspan) return;
      var maxRowIndex = rowIndex + (cellSpans.rowspan || 1);
      var maxColIndex = colIndex + (cellSpans.colspan || 1);

      for (var i = rowIndex; i < maxRowIndex; i++) {
        for (var j = colIndex; j < maxColIndex; j++) {
          if (i !== rowIndex || j !== colIndex) {
            skipSpansMap.set([i, j].join(), true);
          }
        }
      }
    };

    var columnLength = this.columns.length;
    var dataLength = this.data.length;
    var trNodeList = [];
    skipSpansMap = /* @__PURE__ */new Map();
    var properties = ["rowAndColFixedPosition", "scroll", "tableElm", "tableContentElm", "trs", "bufferSize", "isVirtual", "rowHeight", "scrollType"];
    (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.forEach(function (row, rowIndex) {
      var trProps = _objectSpread(_objectSpread(_objectSpread({}, pick(_this.$props, TABLE_PROPS)), {}, {
        row: row,
        columns: _this.columns,
        rowIndex: rowIndex,
        dataLength: dataLength,
        skipSpansMap: skipSpansMap
      }, pick(_this.$props, properties)), {}, {
        onTrRowspanOrColspan: onTrRowspanOrColspan
      });

      if (_this.onCellClick) {
        trProps.onCellClick = _this.onCellClick;
      }

      var on = _this.getTrListeners();

      if (_this.handleRowMounted) {
        on.onRowMounted = _this.handleRowMounted;
      }

      var trNode = h(TrElement, helper([{
        "scopedSlots": _this.$scopedSlots,
        "key": get(row, _this.rowKey || "id")
      }, {
        "on": on
      }, {}, {
        "props": trProps
      }]));
      trNodeList.push(trNode);

      if (_this.renderExpandedRow) {
        var p = {
          row: row,
          index: rowIndex,
          columns: _this.columns,
          tableWidth: _this.tableWidth,
          isWidthOverflow: _this.isWidthOverflow
        };

        var expandedContent = _this.renderExpandedRow(h, p);

        expandedContent && trNodeList.push(expandedContent);
      }
    });
    var list = [getFullRow(h, columnLength, "first-full-row"), trNodeList, getFullRow(h, columnLength, "last-full-row")];
    var isEmpty = !((_this$data2 = this.data) !== null && _this$data2 !== void 0 && _this$data2.length) && !this.loading;
    var translate = "translate(0, ".concat(this.translateY, "px)");
    var posStyle = {
      transform: translate,
      "-ms-transform": translate,
      "-moz-transform": translate,
      "-webkit-transform": translate
    };
    return h("tbody", {
      "class": this.tbodyClasses,
      "style": this.isVirtual && _objectSpread({}, posStyle)
    }, [isEmpty ? renderEmpty(h, this.columns) : list]);
  }
});

export { ROW_AND_TD_LISTENERS, TBody as default, extendTableProps };
//# sourceMappingURL=tbody.js.map
