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

import { h as helper } from '../../../_chunks/dep-29915b8e.js';
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 { useLNodeJSX } from '../../../hooks/lnode.js';
import useClassName from '../hooks/useClassName.js';
import { BaseTableProps } from '../props.js';
import useRowspanAndColspan from '../hooks/useRowspanAndColspan.js';
import TrElement, { TABLE_PROPS, ROW_LISTENERS } from './tr.js';
import '../../config-provider/context.js';
import 'lodash';
import '../../../_chunks/dep-def4c2ce.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import 'lodash/kebabCase';
import '../../../hooks/render-lnode.js';
import '../../../_chunks/dep-70c789e5.js';
import '../../../_chunks/dep-5210251b.js';
import 'lodash/upperFirst';
import 'lodash/isString';
import '../../../hooks/use-lazy-load.js';
import '../../../_chunks/dep-356f585c.js';
import '../utils.js';
import 'lodash/isObject';
import '../hooks/useFixed.js';
import 'lodash/debounce';
import '../../../_chunks/dep-47d77fc8.js';
import '../../../utils/dom.js';
import 'vue';
import 'raf';
import '../../../utils/easing.js';
import './ellipsis.js';
import '../../../utils/render-node.js';
import '../../tooltip/index.js';
import '../../../utils/map-props.js';
import '../../../utils/with-install.js';
import '../../../config.js';
import '../../tooltip/tooltip.js';
import '../../popup/props.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../../_chunks/dep-cf772670.js';
import '../../../utils/helper.js';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../../utils/mixins.js';
import '../../popup/container.js';
import '../../tooltip/props.js';

const ROW_AND_TD_LISTENERS = ROW_LISTENERS.concat("cell-click");
const extendTableProps = ["rowKey", "rowClassName", "rowAttributes", "loading", "empty", "fixedRows", "firstFullRow", "lastFullRow", "rowspanAndColspan", "scroll", "cellEmptyContent", "onCellClick", "onPageChange", "onRowClick", "onRowDblclick", "onRowMouseover", "onRowMousedown", "onRowMouseenter", "onRowMouseleave", "onRowMouseup", "onScroll", "onScrollX", "onScrollY"];
var TBody = defineComponent({
  name: "TBody",
  props: {
    classPrefix: String,
    ellipsisOverlayClassName: String,
    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(props, _ref) {
    let {
      emit
    } = _ref;
    const renderLNode = useLNodeJSX();
    const {
      data,
      columns,
      rowKey,
      rowspanAndColspan
    } = toRefs(props);
    const {
      t,
      global
    } = useConfig("table");
    const {
      tableFullRowClasses,
      tableBaseClass
    } = useClassName();
    const {
      skipSpansMap
    } = useRowspanAndColspan(data, columns, rowKey, rowspanAndColspan);
    const tbodyClasses = computed(() => [tableBaseClass.body]);
    const isFixedLeftColumn = computed(() => props.isWidthOverflow && !!props.columns.find(col => col.fixed === "left"));
    const getTrListeners = () => {
      const trListeners = {};
      ROW_AND_TD_LISTENERS.forEach(eventName => {
        const name = ["cell-click"].includes(eventName) ? eventName : `row-${eventName}`;
        trListeners[name] = context => {
          emit(name, context);
        };
      });
      return trListeners;
    };
    return {
      t,
      global,
      tableFullRowClasses,
      tbodyClasses,
      tableBaseClass,
      isFixedLeftColumn,
      skipSpansMap,
      renderLNode,
      getTrListeners
    };
  },
  render(h) {
    var _this$data, _this$data2;
    const renderEmpty = (h2, columns) => {
      return h("tr", {
        "class": [this.tableBaseClass.emptyRow, {
          [this.tableFullRowClasses.base]: this.isWidthOverflow
        }]
      }, [h("td", {
        "attrs": {
          "colspan": columns.length
        }
      }, [h("div", {
        "class": [this.tableBaseClass.empty, {
          [this.tableFullRowClasses.innerFullRow]: this.isWidthOverflow
        }],
        "style": this.isWidthOverflow ? {
          width: `${this.tableWidth}px`
        } : {}
      }, [this.renderLNode("empty") || this.t(this.global.empty)])])]);
    };
    const getFullRow = (h2, columnLength2, type) => {
      const tType = camelCase(type);
      const fullRowNode = this.renderLNode(tType);
      if (["", null, void 0, false].includes(fullRowNode)) return null;
      const classes = [this.tableFullRowClasses.base, this.tableFullRowClasses[tType]];
      return h("tr", {
        "class": classes
      }, [h("td", {
        "attrs": {
          "colspan": columnLength2
        }
      }, [h("div", {
        "class": {
          [this.tableFullRowClasses.innerFullRow]: this.isFixedToLeft
        },
        "style": this.isFixedToLeft ? {
          width: `${this.tableWidth}px`
        } : {}
      }, [h("div", {
        "class": this.tableFullRowClasses.innerFullElement
      }, [fullRowNode])])])]);
    };
    const columnLength = this.columns.length;
    const dataLength = this.data.length;
    const trNodeList = [];
    const properties = ["classPrefix", "ellipsisOverlayClassName", "rowAndColFixedPosition", "scroll", "tableElm", "tableContentElm", "trs", "bufferSize", "isVirtual", "rowHeight", "scrollType"];
    (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.forEach((row, rowIndex) => {
      const trProps = {
        ...pick(this.$props, TABLE_PROPS),
        row,
        columns: this.columns,
        rowIndex,
        dataLength,
        skipSpansMap: this.skipSpansMap,
        ...pick(this.$props, properties)
      };
      if (this.onCellClick) trProps.onCellClick = this.onCellClick;
      const on = this.getTrListeners();
      if (this.handleRowMounted) on.onRowMounted = this.handleRowMounted;
      const trNode = h(TrElement, helper([{
        "scopedSlots": this.$scopedSlots,
        "key": get(row, this.rowKey || "id")
      }, {
        "on": on
      }, {}, {
        "props": trProps
      }]));
      trNodeList.push(trNode);
      if (this.renderExpandedRow) {
        const p = {
          row,
          index: rowIndex,
          columns: this.columns,
          tableWidth: this.tableWidth,
          isWidthOverflow: this.isWidthOverflow
        };
        const expandedContent = this.renderExpandedRow(h, p);
        expandedContent && trNodeList.push(expandedContent);
      }
    });
    const list = [getFullRow(h, columnLength, "first-full-row"), trNodeList, getFullRow(h, columnLength, "last-full-row")];
    const isEmpty = !((_this$data2 = this.data) !== null && _this$data2 !== void 0 && _this$data2.length) && !this.loading && !this.firstFullRow && !this.lastFullRow;
    const translate = `translate(0, ${this.translateY}px)`;
    const posStyle = {
      "transform": translate,
      "-ms-transform": translate,
      "-moz-transform": translate,
      "-webkit-transform": translate
    };
    return h("tbody", {
      "class": this.tbodyClasses,
      "style": this.isVirtual && {
        ...posStyle
      }
    }, [isEmpty ? renderEmpty(h, this.columns) : list]);
  }
});

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