/**
 * 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 camelCase = require('lodash/camelCase');
var get = require('lodash/get');
var pick = require('lodash/pick');
var components_configProvider_useConfig = require('../../config-provider/useConfig.js');
var hooks_lnode = require('../../../hooks/lnode.js');
var components_table_hooks_useClassName = require('../hooks/useClassName.js');
var components_table_props = require('../props.js');
var components_table_hooks_useRowspanAndColspan = require('../hooks/useRowspanAndColspan.js');
var components_table_core_tr = require('./tr.js');
require('../../config-provider/context.js');
require('lodash');
require('../../../chunks/zh_CN.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/kebabCase');
require('../../../hooks/render-lnode.js');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('lodash/upperFirst');
require('lodash/isString');
require('../../../hooks/use-lazy-load.js');
require('../../../chunks/observe.js');
require('../utils.js');
require('lodash/isObject');
require('../hooks/useFixed.js');
require('lodash/debounce');
require('../../../chunks/helper2.js');
require('../../../utils/dom.js');
require('vue');
require('raf');
require('../../../utils/easing.js');
require('./ellipsis.js');
require('../../../utils/render-node.js');
require('../../tooltip/index.js');
require('../../../utils/map-props.js');
require('../../../utils/with-install.js');
require('../../../config.js');
require('../../tooltip/tooltip.js');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../../chunks/set-style.js');
require('../../../utils/helper.js');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../../utils/mixins.js');
require('../../popup/container.js');
require('../../tooltip/props.js');

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

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

const ROW_AND_TD_LISTENERS = components_table_core_tr.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 = VueCompositionAPI.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__default["default"](components_table_props.BaseTableProps, extendTableProps)
  },
  setup(props, _ref) {
    let {
      emit
    } = _ref;
    const renderLNode = hooks_lnode.useLNodeJSX();
    const {
      data,
      columns,
      rowKey,
      rowspanAndColspan
    } = VueCompositionAPI.toRefs(props);
    const {
      t,
      global
    } = components_configProvider_useConfig.useConfig("table");
    const {
      tableFullRowClasses,
      tableBaseClass
    } = components_table_hooks_useClassName["default"]();
    const {
      skipSpansMap
    } = components_table_hooks_useRowspanAndColspan["default"](data, columns, rowKey, rowspanAndColspan);
    const tbodyClasses = VueCompositionAPI.computed(() => [tableBaseClass.body]);
    const isFixedLeftColumn = VueCompositionAPI.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__default["default"](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__default["default"](this.$props, components_table_core_tr.TABLE_PROPS),
        row,
        columns: this.columns,
        rowIndex,
        dataLength,
        skipSpansMap: this.skipSpansMap,
        ...pick__default["default"](this.$props, properties)
      };
      if (this.onCellClick) trProps.onCellClick = this.onCellClick;
      const on = this.getTrListeners();
      if (this.handleRowMounted) on.onRowMounted = this.handleRowMounted;
      const trNode = h(components_table_core_tr["default"], helper.helper([{
        "scopedSlots": this.$scopedSlots,
        "key": get__default["default"](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]);
  }
});

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