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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var camelCase = require('lodash/camelCase');
var get = require('lodash/get');
var pick = require('lodash/pick');
var configProvider_useConfig = require('../config-provider/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var table_tr = require('./tr.js');
var table_hooks_useClassName = require('./hooks/useClassName.js');
var table_baseTableProps = require('./base-table-props.js');
var table_hooks_useRowspanAndColspan = require('./hooks/useRowspanAndColspan.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/upperFirst');
require('./utils.js');
require('./hooks/useFixed.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isUndefined');
require('lodash/debounce');
require('../_common/js/log/log.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isNull');
require('lodash/isNumber');
require('../utils/dom.js');
require('../utils/easing.js');
require('./ellipsis.js');
require('../tooltip/index.js');
require('../utils/withInstall.js');
require('../tooltip/tooltip.js');
require('lodash/omit');
require('../popup/props.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../hooks/useConfig.js');
require('../_common/js/utils/set-style.js');
require('../hooks/useVModel.js');
require('../popup/container.js');
require('../hooks/useResizeObserver.js');
require('../tooltip/util.js');
require('../tooltip/props.js');
require('./hooks/useLazyLoad.js');
require('../_common/js/utils/observe.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase);
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
var pick__default = /*#__PURE__*/_interopDefaultLegacy(pick);

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__default["default"](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 = table_tr.ROW_LISTENERS.concat("cell-click");
var extendTableProps = ["rowKey", "rowClassName", "rowAttributes", "loading", "empty", "fixedRows", "firstFullRow", "lastFullRow", "rowspanAndColspan", "scroll", "cellEmptyContent", "pagination", "attach", "onCellClick", "onPageChange", "onRowClick", "onRowDblclick", "onRowMouseover", "onRowMousedown", "onRowMouseenter", "onRowMouseleave", "onRowMouseup", "onScroll", "onScrollX", "onScrollY"];
var TBody = vue.defineComponent({
  name: "TBody",
  props: _objectSpread({
    classPrefix: String,
    data: Array,
    columns: Array,
    ellipsisOverlayClassName: String,
    rowAndColFixedPosition: Map,
    showColumnShadow: Object,
    tableElm: {},
    tableWidth: Number,
    isWidthOverflow: Boolean,
    virtualConfig: Object,
    tableContentElm: {},
    handleRowMounted: Function,
    renderExpandedRow: Function,
    firstFullRow: [String, Function],
    lastFullRow: [String, Function]
  }, pick__default["default"](table_baseTableProps["default"], extendTableProps)),
  setup: function setup(props) {
    var renderTNode = hooks_tnode.useTNodeJSX();
    var _toRefs = vue.toRefs(props),
      data = _toRefs.data,
      columns = _toRefs.columns,
      rowKey = _toRefs.rowKey,
      rowspanAndColspan = _toRefs.rowspanAndColspan;
    var _useConfig = configProvider_useConfig.useConfig("table"),
      t = _useConfig.t,
      globalConfig = _useConfig.globalConfig;
    var _useClassName = table_hooks_useClassName["default"](),
      tableFullRowClasses = _useClassName.tableFullRowClasses,
      tableBaseClass = _useClassName.tableBaseClass;
    var _useRowspanAndColspan = table_hooks_useRowspanAndColspan["default"](data, columns, rowKey, rowspanAndColspan),
      skipSpansMap = _useRowspanAndColspan.skipSpansMap;
    var tbodyClasses = vue.computed(function () {
      return [tableBaseClass.body];
    });
    return {
      t: t,
      globalConfig: globalConfig,
      renderTNode: renderTNode,
      tableFullRowClasses: tableFullRowClasses,
      tbodyClasses: tbodyClasses,
      tableBaseClass: tableBaseClass,
      skipSpansMap: skipSpansMap
    };
  },
  render: function render() {
    var _this = this,
      _this$data,
      _this$data2,
      _this$virtualConfig,
      _this$virtualConfig2;
    var renderEmpty = function renderEmpty(columns) {
      return vue.createVNode("tr", {
        "class": [_this.tableBaseClass.emptyRow, _defineProperty__default["default"]({}, _this.tableFullRowClasses.base, _this.isWidthOverflow)]
      }, [vue.createVNode("td", {
        "colspan": columns.length
      }, [vue.createVNode("div", {
        "class": [_this.tableBaseClass.empty, _defineProperty__default["default"]({}, _this.tableFullRowClasses.innerFullRow, _this.isWidthOverflow)],
        "style": _this.isWidthOverflow ? {
          width: "".concat(_this.tableWidth, "px")
        } : {}
      }, [_this.renderTNode("empty") || _this.t(_this.globalConfig.empty)])])]);
    };
    var getFullRow = function getFullRow(columnLength2, type) {
      var tType = camelCase__default["default"](type);
      var fullRowNode = _this.renderTNode(tType);
      if (["", null, void 0, false].includes(fullRowNode)) return null;
      var isFixedToLeft = _this.isWidthOverflow && _this.columns.find(function (col) {
        return col.fixed === "left";
      });
      var classes = [_this.tableFullRowClasses.base, _this.tableFullRowClasses[tType]];
      return vue.createVNode("tr", {
        "class": classes,
        "key": "key-full-row-".concat(type)
      }, [vue.createVNode("td", {
        "colspan": columnLength2
      }, [vue.createVNode("div", {
        "class": _defineProperty__default["default"]({}, _this.tableFullRowClasses.innerFullRow, isFixedToLeft),
        "style": isFixedToLeft ? {
          width: "".concat(_this.tableWidth, "px")
        } : {}
      }, [vue.createVNode("div", {
        "class": _this.tableFullRowClasses.innerFullElement
      }, [fullRowNode])])])]);
    };
    var columnLength = this.columns.length;
    var dataLength = this.data.length;
    var trNodeList = [];
    var properties = ["classPrefix", "ellipsisOverlayClassName", "rowAndColFixedPosition", "scroll", "tableElm", "tableContentElm", "pagination", "attach"];
    (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.forEach(function (row, rowIndex) {
      var trProps = _objectSpread(_objectSpread({}, pick__default["default"](_this.$props, table_tr.TABLE_PROPS)), {}, {
        rowKey: _this.rowKey || "id",
        row: row,
        columns: _this.columns,
        rowIndex: row.__VIRTUAL_SCROLL_INDEX || rowIndex,
        dataLength: dataLength,
        skipSpansMap: _this.skipSpansMap,
        virtualConfig: _this.virtualConfig
      }, pick__default["default"](_this.$props, properties));
      if (_this.onCellClick) trProps.onCellClick = _this.onCellClick;
      var trNode = vue.createVNode(table_tr["default"], vue.mergeProps({
        "key": get__default["default"](row, _this.rowKey || "id") || rowIndex
      }, trProps, {
        "onRowMounted": _this.handleRowMounted
      }), _this.$slots);
      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(p);
        expandedContent && trNodeList.push(expandedContent);
      }
    });
    var list = [getFullRow(columnLength, "first-full-row")].concat(trNodeList, [getFullRow(columnLength, "last-full-row")]);
    var isEmpty = !((_this$data2 = this.data) !== null && _this$data2 !== void 0 && _this$data2.length) && !this.loading && !this.firstFullRow && !this.lastFullRow;
    var translate = "translateY(".concat((_this$virtualConfig = this.virtualConfig) === null || _this$virtualConfig === void 0 ? void 0 : _this$virtualConfig.translateY.value, "px)");
    var posStyle = (_this$virtualConfig2 = this.virtualConfig) !== null && _this$virtualConfig2 !== void 0 && _this$virtualConfig2.isVirtualScroll.value ? {
      "transform": translate,
      "-ms-transform": translate,
      "-moz-transform": translate,
      "-webkit-transform": translate
    } : void 0;
    return vue.createVNode("tbody", {
      "class": this.tbodyClasses,
      "style": _objectSpread({}, posStyle)
    }, [isEmpty ? renderEmpty(this.columns) : list]);
  }
});

exports.ROW_AND_TD_LISTENERS = ROW_AND_TD_LISTENERS;
exports["default"] = TBody;
exports.extendTableProps = extendTableProps;
//# sourceMappingURL=tbody.js.map
