/**
 * 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, ref, computed, watch, nextTick, toRefs, provide, onMounted } from '@vue/composition-api';
import pick from 'lodash/pick';
import baseTableProps from './base-table-props.js';
import useTableHeader from './hooks/useTableHeader.js';
import useColumnResize from './hooks/useColumnResize.js';
import useFixed from './hooks/useFixed.js';
import usePagination from './hooks/usePagination.js';
import useVirtualScroll from '../hooks/useVirtualScroll.js';
import { Loading } from '../loading/index.js';
import TBody, { extendTableProps } from './tbody.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import useStyle, { formatCSSUnit } from './hooks/useStyle.js';
import useClassName from './hooks/useClassName.js';
import { useConfig } from '../config-provider/useConfig.js';
import { Affix } from '../affix/index.js';
import { ROW_LISTENERS } from './tr.js';
import THead from './thead.js';
import TFoot from './tfoot.js';
import '@babel/runtime/helpers/typeof';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isString';
import 'lodash/isFunction';
import './hooks/useMultiHeader.js';
import './ellipsis.js';
import 'lodash/debounce';
import '../utils/render-tnode.js';
import 'vue';
import '../utils/dom.js';
import 'raf';
import '../utils/easing.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 'lodash/camelCase';
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/index.js';
import '../popup/type.js';
import 'lodash/get';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../_common/js/utils/getScrollbarWidth.js';
import '../pagination/index.js';
import '../pagination/pagination.js';
import 'tdesign-icons-vue';
import '../utils/mixins.js';
import '../config-provider/config-receiver.js';
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 '../input-number/index.js';
import '../input-number/input-number.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '../button/index.js';
import '../button/button.js';
import '../button/props.js';
import '../utils/ripple.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/helper.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../button/type.js';
import '../input/index.js';
import '../input/addon.js';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/kebabCase';
import '../utils/event.js';
import '../input/props.js';
import '../input/input-group.js';
import '../input/type.js';
import '../input-number/props.js';
import '../input-number/type.js';
import '../select/index.js';
import '../select/select.js';
import 'lodash/set';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag/type.js';
import '../common-components/fake-arrow.js';
import '../select/option.js';
import '../select/option-props.js';
import '../checkbox/index.js';
import '../checkbox/group.js';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/type.js';
import '../select/props.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../select/type.js';
import '../pagination/props.js';
import '../pagination/type.js';
import 'lodash/isEmpty';
import '../hooks/render-tnode.js';
import 'lodash/isObject';
import '../hooks/useCommonClassName.js';
import 'lodash/cloneDeep';
import '../affix/affix.js';
import '../affix/props.js';
import '../affix/type.js';
import 'lodash/upperFirst';
import './utils.js';
import './hooks/useLazyLoad.js';
import '../_common/js/utils/observe.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 BASE_TABLE_EVENTS = ["page-change", "cell-click", "scroll", "scrollX", "scrollY"];
var BASE_TABLE_ALL_EVENTS = ROW_LISTENERS.map(function (t) {
  return "row-".concat(t);
}).concat(BASE_TABLE_EVENTS);
var _BaseTable = defineComponent({
  name: "TBaseTable",
  props: _objectSpread(_objectSpread({}, baseTableProps), {}, {
    renderExpandedRow: Function
  }),
  setup: function setup(props2, context) {
    var _props2$scroll3;

    var renderTNode = useTNodeJSX();
    var tableRef = ref();
    var tableElmRef = ref();
    var tableFootHeight = ref(0);

    var _useClassName = useClassName(),
        virtualScrollClasses = _useClassName.virtualScrollClasses,
        tableLayoutClasses = _useClassName.tableLayoutClasses,
        tableBaseClass = _useClassName.tableBaseClass,
        tableColFixedClasses = _useClassName.tableColFixedClasses;

    var _useStyle = useStyle(props2),
        tableClasses = _useStyle.tableClasses,
        tableContentStyles = _useStyle.tableContentStyles,
        tableElementStyles = _useStyle.tableElementStyles;

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

    var _useFixed = useFixed(props2, context),
        affixHeaderRef = _useFixed.affixHeaderRef,
        affixFooterRef = _useFixed.affixFooterRef,
        scrollbarWidth = _useFixed.scrollbarWidth,
        virtualScrollHeaderPos = _useFixed.virtualScrollHeaderPos,
        tableWidth = _useFixed.tableWidth,
        tableElmWidth = _useFixed.tableElmWidth,
        tableContentRef = _useFixed.tableContentRef,
        isFixedHeader = _useFixed.isFixedHeader,
        isWidthOverflow = _useFixed.isWidthOverflow,
        isFixedColumn = _useFixed.isFixedColumn,
        thWidthList = _useFixed.thWidthList,
        showColumnShadow = _useFixed.showColumnShadow,
        showAffixHeader = _useFixed.showAffixHeader,
        showAffixFooter = _useFixed.showAffixFooter,
        rowAndColFixedPosition = _useFixed.rowAndColFixedPosition,
        refreshTable = _useFixed.refreshTable,
        updateHeaderScroll = _useFixed.updateHeaderScroll,
        setUseFixedTableElmRef = _useFixed.setUseFixedTableElmRef;

    var _useTableHeader = useTableHeader(props2),
        isMultipleHeader = _useTableHeader.isMultipleHeader,
        spansAndLeafNodes = _useTableHeader.spansAndLeafNodes,
        thList = _useTableHeader.thList;

    var _usePagination = usePagination(props2, context),
        dataSource = _usePagination.dataSource,
        isPaginateData = _usePagination.isPaginateData,
        renderPagination = _usePagination.renderPagination;

    var columnResizeParams = useColumnResize(tableElmRef, refreshTable);
    var resizeLineRef = columnResizeParams.resizeLineRef,
        resizeLineStyle = columnResizeParams.resizeLineStyle;
    var dynamicBaseTableClasses = computed(function () {
      var _ref;

      return [tableClasses.value, (_ref = {}, _defineProperty(_ref, tableBaseClass.headerFixed, isFixedHeader.value), _defineProperty(_ref, tableBaseClass.columnFixed, isFixedColumn.value), _defineProperty(_ref, tableBaseClass.widthOverflow, isWidthOverflow.value), _defineProperty(_ref, tableBaseClass.multipleHeader, isMultipleHeader.value), _defineProperty(_ref, tableColFixedClasses.leftShadow, showColumnShadow.left), _defineProperty(_ref, tableColFixedClasses.rightShadow, showColumnShadow.right), _ref)];
    });
    var tableElmClasses = computed(function () {
      return [[tableLayoutClasses[props2.tableLayout]], _defineProperty({}, tableBaseClass.fullHeight, props2.height)];
    });
    var isVirtual = computed(function () {
      var _props2$scroll, _props2$data, _props2$scroll2;

      return ((_props2$scroll = props2.scroll) === null || _props2$scroll === void 0 ? void 0 : _props2$scroll.type) === "virtual" && ((_props2$data = props2.data) === null || _props2$data === void 0 ? void 0 : _props2$data.length) > (((_props2$scroll2 = props2.scroll) === null || _props2$scroll2 === void 0 ? void 0 : _props2$scroll2.threshold) || 100);
    });
    var showRightDivider = computed(function () {
      return props2.bordered && isFixedHeader.value && (isMultipleHeader.value && isWidthOverflow.value || !isMultipleHeader.value);
    });
    watch(tableElmRef, function () {
      setUseFixedTableElmRef(tableElmRef.value);
    });

    var onFixedChange = function onFixedChange() {
      nextTick(function () {
        updateHeaderScroll();
      });
    };

    var getListener = function getListener() {
      var listener = {};
      BASE_TABLE_ALL_EVENTS.forEach(function (key) {
        listener[key] = function () {
          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }

          context.emit.apply(context, [key].concat(args));
        };
      });
      return listener;
    };

    var _ref3 = props2.scroll || {},
        type = _ref3.type,
        rowHeight = _ref3.rowHeight,
        _ref3$bufferSize = _ref3.bufferSize,
        bufferSize = _ref3$bufferSize === void 0 ? 20 : _ref3$bufferSize,
        _ref3$isFixedRowHeigh = _ref3.isFixedRowHeight,
        isFixedRowHeight = _ref3$isFixedRowHeigh === void 0 ? false : _ref3$isFixedRowHeigh;

    var _toRefs = toRefs(props2),
        data = _toRefs.data;

    var _ref4 = type === "virtual" ? useVirtualScroll({
      container: tableContentRef,
      data: data,
      fixedHeight: isFixedRowHeight,
      lineHeight: rowHeight,
      bufferSize: bufferSize,
      threshold: (_props2$scroll3 = props2.scroll) === null || _props2$scroll3 === void 0 ? void 0 : _props2$scroll3.threshold
    }) : {},
        _ref4$trs = _ref4.trs,
        trs = _ref4$trs === void 0 ? null : _ref4$trs,
        _ref4$scrollHeight = _ref4.scrollHeight,
        scrollHeight = _ref4$scrollHeight === void 0 ? null : _ref4$scrollHeight,
        _ref4$visibleData = _ref4.visibleData,
        visibleData = _ref4$visibleData === void 0 ? null : _ref4$visibleData,
        _ref4$translateY = _ref4.translateY,
        translateY = _ref4$translateY === void 0 ? null : _ref4$translateY,
        _ref4$handleScroll = _ref4.handleScroll,
        handleVirtualScroll = _ref4$handleScroll === void 0 ? null : _ref4$handleScroll,
        _ref4$handleRowMounte = _ref4.handleRowMounted,
        handleRowMounted = _ref4$handleRowMounte === void 0 ? null : _ref4$handleRowMounte;

    provide("tableContentRef", tableContentRef);
    provide("rowHeightRef", ref(rowHeight));
    var lastScrollY = -1;

    var onInnerVirtualScroll = function onInnerVirtualScroll(e) {
      var target = e.target || e.srcElement;
      var top = target.scrollTop;

      if (Math.abs(lastScrollY - top) > 5) {
        handleVirtualScroll();
        lastScrollY = top;
      } else {
        lastScrollY = -1;
      }
    };

    var getTFootHeight = function getTFootHeight() {
      var _tableElmRef$value$qu;

      if (!tableElmRef.value) return;
      tableFootHeight.value = (_tableElmRef$value$qu = tableElmRef.value.querySelector("tfoot")) === null || _tableElmRef$value$qu === void 0 ? void 0 : _tableElmRef$value$qu.offsetHeight;
    };

    onMounted(function () {
      getTFootHeight();
    });
    return {
      thList: thList,
      isVirtual: isVirtual,
      global: global,
      tableFootHeight: tableFootHeight,
      virtualScrollHeaderPos: virtualScrollHeaderPos,
      tableWidth: tableWidth,
      tableElmWidth: tableElmWidth,
      tableRef: tableRef,
      tableElmRef: tableElmRef,
      tableBaseClass: tableBaseClass,
      spansAndLeafNodes: spansAndLeafNodes,
      dynamicBaseTableClasses: dynamicBaseTableClasses,
      tableContentStyles: tableContentStyles,
      tableElementStyles: tableElementStyles,
      virtualScrollClasses: virtualScrollClasses,
      tableLayoutClasses: tableLayoutClasses,
      tableElmClasses: tableElmClasses,
      tableContentRef: tableContentRef,
      isFixedHeader: isFixedHeader,
      isWidthOverflow: isWidthOverflow,
      isFixedColumn: isFixedColumn,
      rowAndColFixedPosition: rowAndColFixedPosition,
      showColumnShadow: showColumnShadow,
      thWidthList: thWidthList,
      isPaginateData: isPaginateData,
      dataSource: dataSource,
      scrollType: type,
      rowHeight: rowHeight,
      trs: trs,
      bufferSize: bufferSize,
      scrollHeight: scrollHeight,
      visibleData: visibleData,
      translateY: translateY,
      affixHeaderRef: affixHeaderRef,
      affixFooterRef: affixFooterRef,
      showAffixHeader: showAffixHeader,
      showAffixFooter: showAffixFooter,
      scrollbarWidth: scrollbarWidth,
      isMultipleHeader: isMultipleHeader,
      showRightDivider: showRightDivider,
      resizeLineRef: resizeLineRef,
      resizeLineStyle: resizeLineStyle,
      columnResizeParams: columnResizeParams,
      getListener: getListener,
      renderPagination: renderPagination,
      renderTNode: renderTNode,
      handleRowMounted: handleRowMounted,
      onFixedChange: onFixedChange,
      updateHeaderScroll: updateHeaderScroll,
      refreshTable: refreshTable,
      onInnerVirtualScroll: onInnerVirtualScroll
    };
  },
  render: function render(h) {
    var _this$spansAndLeafNod,
        _this$footData,
        _this = this;

    var rowAndColFixedPosition = this.rowAndColFixedPosition;
    var data = this.isPaginateData ? this.dataSource : this.data;
    var defaultColWidth = this.tableLayout === "fixed" && this.isWidthOverflow ? "100px" : void 0;
    var colgroup = h("colgroup", [(((_this$spansAndLeafNod = this.spansAndLeafNodes) === null || _this$spansAndLeafNod === void 0 ? void 0 : _this$spansAndLeafNod.leafColumns) || this.columns).map(function (col) {
      return h("col", {
        "key": col.colKey,
        "style": {
          width: formatCSSUnit(col.width) || defaultColWidth
        }
      });
    })]);
    var affixedHeader = Boolean((this.headerAffixedTop || this.isVirtual) && this.tableWidth) && h("div", {
      "ref": "affixHeaderRef",
      "style": {
        width: "".concat(this.tableWidth, "px"),
        opacity: Number(this.showAffixHeader)
      },
      "class": _defineProperty({}, this.tableBaseClass.affixedHeaderElm, this.headerAffixedTop || this.isVirtual)
    }, [h("table", {
      "class": this.tableElmClasses,
      "style": _objectSpread(_objectSpread({}, this.tableElementStyles), {}, {
        width: "".concat(this.tableElmWidth, "px")
      })
    }, [colgroup, h(THead, {
      "scopedSlots": this.$scopedSlots,
      "attrs": {
        "isFixedHeader": this.isFixedHeader,
        "rowAndColFixedPosition": this.rowAndColFixedPosition,
        "isMultipleHeader": this.isMultipleHeader,
        "bordered": this.bordered,
        "spansAndLeafNodes": this.spansAndLeafNodes,
        "thList": this.thList,
        "thWidthList": this.thWidthList,
        "allowResizeColumnWidth": this.allowResizeColumnWidth,
        "columnResizeParams": this.columnResizeParams
      }
    })])]);
    var marginScrollbarWidth = this.isWidthOverflow ? this.scrollbarWidth : 0;

    if (this.bordered) {
      marginScrollbarWidth += 1;
    }

    var affixedFooter = Boolean(this.footerAffixedBottom && ((_this$footData = this.footData) === null || _this$footData === void 0 ? void 0 : _this$footData.length) && this.tableWidth) && h(Affix, helper([{
      "class": this.tableBaseClass.affixedFooterWrap
    }, {
      "props": this.footerAffixProps
    }, {
      "on": {
        "fixedChange": this.onFixedChange
      },
      "attrs": {
        "offsetBottom": marginScrollbarWidth || 0
      },
      "style": {
        marginTop: "".concat(-1 * (this.tableFootHeight + marginScrollbarWidth), "px")
      }
    }]), [h("div", {
      "ref": "affixFooterRef",
      "style": {
        width: "".concat(this.tableWidth, "px"),
        opacity: Number(this.showAffixFooter)
      },
      "class": ["scrollbar", _defineProperty({}, this.tableBaseClass.affixedFooterElm, this.footerAffixedBottom || this.isVirtual)]
    }, [h("table", {
      "class": this.tableElmClasses,
      "style": _objectSpread(_objectSpread({}, this.tableElementStyles), {}, {
        width: "".concat(this.tableElmWidth, "px")
      })
    }, [colgroup, h(TFoot, {
      "attrs": {
        "rowKey": this.rowKey,
        "isFixedHeader": this.isFixedHeader,
        "rowAndColFixedPosition": rowAndColFixedPosition,
        "footData": this.footData,
        "columns": this.columns,
        "rowAttributes": this.rowAttributes,
        "rowClassName": this.rowClassName,
        "thWidthList": this.thWidthList
      },
      "scopedSlots": this.$scopedSlots
    })])])]);
    var translate = "translate(0, ".concat(this.scrollHeight, "px)");
    var virtualStyle = {
      transform: translate,
      "-ms-transform": translate,
      "-moz-transform": translate,
      "-webkit-transform": translate
    };

    var tableBodyProps = _objectSpread({
      rowAndColFixedPosition: rowAndColFixedPosition,
      showColumnShadow: this.showColumnShadow,
      data: this.isVirtual ? this.visibleData : data,
      columns: this.spansAndLeafNodes.leafColumns,
      tableElm: this.tableRef,
      tableWidth: this.tableWidth,
      isWidthOverflow: this.isWidthOverflow,
      isVirtual: this.isVirtual,
      translateY: this.translateY,
      scrollType: this.scrollType,
      rowHeight: this.rowHeight,
      trs: this.trs,
      bufferSize: this.bufferSize,
      scroll: this.scroll,
      tableContentElm: this.tableContentRef,
      handleRowMounted: this.handleRowMounted,
      renderExpandedRow: this.renderExpandedRow
    }, pick(this.$props, extendTableProps));

    var on = this.getListener();
    var scrollListener = this.isVirtual ? {
      scroll: this.onInnerVirtualScroll
    } : {};
    var tableContent = h("div", helper([{
      "ref": "tableContentRef",
      "class": this.tableBaseClass.content,
      "style": this.tableContentStyles
    }, {
      "on": scrollListener
    }]), [h("div", {
      "ref": "resizeLineRef",
      "class": this.tableBaseClass.resizeLine,
      "style": this.resizeLineStyle
    }), this.isVirtual && h("div", {
      "class": this.virtualScrollClasses.cursor,
      "style": virtualStyle
    }), h("table", {
      "ref": "tableElmRef",
      "class": this.tableElmClasses,
      "style": this.tableElementStyles
    }, [colgroup, h(THead, {
      "scopedSlots": this.$scopedSlots,
      "attrs": {
        "isFixedHeader": this.isFixedHeader,
        "rowAndColFixedPosition": this.rowAndColFixedPosition,
        "isMultipleHeader": this.isMultipleHeader,
        "bordered": this.bordered,
        "spansAndLeafNodes": this.spansAndLeafNodes,
        "thList": this.thList,
        "allowResizeColumnWidth": this.allowResizeColumnWidth,
        "columnResizeParams": this.columnResizeParams
      }
    }), h(TBody, helper([{
      "scopedSlots": this.$scopedSlots
    }, {
      "props": tableBodyProps
    }, {}, {
      "on": on
    }])), h(TFoot, {
      "attrs": {
        "rowKey": this.rowKey,
        "isFixedHeader": this.isFixedHeader,
        "rowAndColFixedPosition": rowAndColFixedPosition,
        "footData": this.footData,
        "columns": this.columns,
        "rowAttributes": this.rowAttributes,
        "rowClassName": this.rowClassName
      },
      "scopedSlots": this.$scopedSlots
    })])]);
    var customLoadingText = this.renderTNode("loading");
    var loadingContent = this.loading !== void 0 && h(Loading, helper([{
      "attrs": {
        "loading": !!this.loading,
        "text": customLoadingText ? function () {
          return customLoadingText;
        } : void 0,
        "attach": this.tableRef ? function () {
          return _this.tableRef;
        } : void 0,
        "showOverlay": true
      }
    }, {
      "props": this.loadingProps
    }]));
    var topContent = this.renderTNode("topContent");
    var bottomContent = this.renderTNode("bottomContent");
    var pagination = this.renderPagination(h);
    var bottom = !!bottomContent && h("div", {
      "class": this.tableBaseClass.bottomContent
    }, [bottomContent]);
    return h("div", {
      "ref": "tableRef",
      "class": this.dynamicBaseTableClasses,
      "style": "position: relative"
    }, [!!topContent && h("div", {
      "class": this.tableBaseClass.topContent
    }, [topContent]), !!(this.isVirtual || this.headerAffixedTop) && (this.headerAffixedTop ? h(Affix, helper([{
      "attrs": {
        "offsetTop": 0
      }
    }, {
      "props": this.headerAffixProps
    }, {
      "on": {
        "fixedChange": this.onFixedChange
      }
    }]), [affixedHeader]) : this.isFixedHeader && affixedHeader), tableContent, loadingContent, affixedFooter, this.showRightDivider && h("div", {
      "class": this.tableBaseClass.scrollbarDivider,
      "style": {
        right: "".concat(this.scrollbarWidth, "px"),
        height: "".concat(this.tableContentRef.offsetHeight, "px")
      }
    }), bottom, pagination]);
  }
});

export { BASE_TABLE_ALL_EVENTS, BASE_TABLE_EVENTS, _BaseTable as default };
//# sourceMappingURL=base-table.js.map
