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

import { h as helper } from '../_chunks/dep-c89aafbb.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, computed } from '@vue/composition-api';
import camelCase from 'lodash/camelCase';
import get from 'lodash/get';
import pick from 'lodash/pick';
import { useConfig } from '../config-provider/useConfig.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import TrElement, { ROW_LISTENERS, TABLE_PROPS } from './tr.js';
import useClassName from './hooks/useClassName.js';
import baseTableProps from './base-table-props.js';
import useRowspanAndColspan from './hooks/useRowspanAndColspan.js';
import '../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../_chunks/dep-67ff4010.js';
import '../config-provider/type.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import 'lodash/kebabCase';
import '../hooks/render-tnode.js';
import 'lodash/isString';
import 'lodash/isObject';
import 'lodash/upperFirst';
import '../hooks/useLazyLoad.js';
import '../_common/js/utils/observe.js';
import './utils.js';
import './hooks/useFixed.js';
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 'vue';
import 'raf';
import '../utils/easing.js';
import './ellipsis.js';
import '../utils/render-tnode.js';
import '../tooltip/index.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import '../tooltip/tooltip.js';
import '../popup/props.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../utils/helper.js';
import '../_common/js/utils/set-style.js';
import '../config-provider/config-receiver.js';
import '../utils/mixins.js';
import '../utils/event.js';
import '../popup/container.js';
import '../popup/utils.js';
import '../popup/trigger.js';
import '../tooltip/props.js';
import '../tooltip/style';
import '../tooltip/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 ROW_AND_TD_LISTENERS = 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 = defineComponent({
  name: "TBody",
  props: _objectSpread({
    classPrefix: String,
    ellipsisOverlayClassName: String,
    data: Array,
    columns: Array,
    rowAndColFixedPosition: Map,
    showColumnShadow: Object,
    tableElm: {},
    tableWidth: Number,
    isWidthOverflow: Boolean,
    virtualConfig: Object,
    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 _toRefs = toRefs(props),
      data = _toRefs.data,
      columns = _toRefs.columns,
      rowKey = _toRefs.rowKey,
      rowspanAndColspan = _toRefs.rowspanAndColspan;
    var _useConfig = useConfig("table"),
      t = _useConfig.t,
      global = _useConfig.global;
    var _useClassName = useClassName(),
      tableFullRowClasses = _useClassName.tableFullRowClasses,
      tableBaseClass = _useClassName.tableBaseClass;
    var _useRowspanAndColspan = useRowspanAndColspan(data, columns, rowKey, rowspanAndColspan),
      skipSpansMap = _useRowspanAndColspan.skipSpansMap;
    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,
      skipSpansMap: skipSpansMap,
      renderTNode: renderTNode,
      getTrListeners: getTrListeners
    };
  },
  render: function render(h) {
    var _this = this,
      _this$data,
      _this$data2,
      _this$data3,
      _this$virtualConfig,
      _this$virtualConfig2;
    var renderEmpty = function renderEmpty(h2, columns) {
      var showEmptyText = Boolean(_this.tableWidth && _this.tableWidth > 100) || process.env.NODE_ENV === "test";
      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")
        } : {}
      }, [showEmptyText ? _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 columnLength = this.columns.length;
    var dataLength = (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.length;
    var trNodeList = [];
    var properties = ["classPrefix", "ellipsisOverlayClassName", "rowAndColFixedPosition", "scroll", "tableElm", "tableContentElm", "pagination", "attach"];
    (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2.forEach(function (row, rowIndex) {
      var trProps = _objectSpread(_objectSpread({}, pick(_this.$props, TABLE_PROPS)), {}, {
        row: row,
        columns: _this.columns,
        rowIndex: (row === null || row === void 0 ? void 0 : row.__VIRTUAL_SCROLL_INDEX) || rowIndex,
        dataLength: dataLength,
        skipSpansMap: _this.skipSpansMap,
        virtualConfig: _this.virtualConfig
      }, pick(_this.$props, properties));
      if (_this.onCellClick) trProps.onCellClick = _this.onCellClick;
      var on = _this.getTrListeners();
      if (_this.handleRowMounted) on["row-mounted"] = _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$data3 = this.data) !== null && _this$data3 !== void 0 && _this$data3.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 h("tbody", {
      "class": this.tbodyClasses,
      "style": _objectSpread({}, posStyle)
    }, [isEmpty ? renderEmpty(h, this.columns) : list]);
  }
});

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