/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-1ec74b8b.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, computed, nextTick, toRefs, provide } from '@vue/composition-api';
import pick from 'lodash/pick';
import baseTableProps from './base-table-props.js';
import useTableHeader from './hooks/useTableHeader.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/slicedToArray';
import 'lodash/isString';
import 'lodash/isFunction';
import './hooks/useMultiHeader.js';
import 'lodash/get';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../_common/js/utils/getScrollbarWidth.js';
import '../utils/dom.js';
import 'vue';
import 'raf';
import '../utils/easing.js';
import '../pagination/index.js';
import '../pagination/pagination.js';
import '@babel/runtime/helpers/typeof';
import 'tdesign-icons-vue';
import '../config.js';
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 '../utils/classnames.js';
import '../button/props.js';
import '../utils/render-tnode.js';
import 'lodash/isObject';
import '../utils/ripple.js';
import '../_common/js/utils/set-style.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.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/camelCase';
import 'lodash/kebabCase';
import '../utils/helper.js';
import '../utils/event.js';
import '../input/props.js';
import '../input/input-group.js';
import '../utils/map-props.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/debounce';
import 'lodash/set';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../popup/type.js';
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 '../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 './ellipsis.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$scroll2;

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

    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,
        scrollbarWidth = _useFixed.scrollbarWidth,
        virtualScrollHeaderPos = _useFixed.virtualScrollHeaderPos,
        tableWidth = _useFixed.tableWidth,
        tableContentRef = _useFixed.tableContentRef,
        isFixedHeader = _useFixed.isFixedHeader,
        isWidthOverflow = _useFixed.isWidthOverflow,
        isFixedColumn = _useFixed.isFixedColumn,
        thWidthList = _useFixed.thWidthList,
        showColumnShadow = _useFixed.showColumnShadow,
        showAffixHeader = _useFixed.showAffixHeader,
        rowAndColFixedPosition = _useFixed.rowAndColFixedPosition,
        refreshTable = _useFixed.refreshTable,
        onTableContentScroll = _useFixed.onTableContentScroll,
        updateHeaderScroll = _useFixed.updateHeaderScroll;

    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 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$data, _props2$scroll;

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

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

    var getListenser = function getListenser() {
      var listenser = {};
      BASE_TABLE_ALL_EVENTS.forEach(function (key) {
        listenser[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 listenser;
    };

    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$scroll2 = props2.scroll) === null || _props2$scroll2 === void 0 ? void 0 : _props2$scroll2.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 onInnerScroll = type === "virtual" ? function (e) {
      onTableContentScroll(e);
      var target = e.target || e.srcElement;
      var top = target.scrollTop;

      if (Math.abs(lastScrollY - top) > 5) {
        handleVirtualScroll();
        lastScrollY = top;
      } else {
        lastScrollY = -1;
      }
    } : onTableContentScroll;
    return {
      thList: thList,
      isVirtual: isVirtual,
      global: global,
      virtualScrollHeaderPos: virtualScrollHeaderPos,
      tableWidth: tableWidth,
      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,
      showAffixHeader: showAffixHeader,
      scrollbarWidth: scrollbarWidth,
      isMultipleHeader: isMultipleHeader,
      showRightDivider: showRightDivider,
      getListenser: getListenser,
      onTableContentScroll: onTableContentScroll,
      renderPagination: renderPagination,
      renderTNode: renderTNode,
      handleRowMounted: handleRowMounted,
      onFixedChange: onFixedChange,
      updateHeaderScroll: updateHeaderScroll,
      onInnerScroll: onInnerScroll,
      refreshTable: refreshTable
    };
  },
  render: function render(h) {
    var _this$spansAndLeafNod;

    var rowAndColFixedPosition = this.rowAndColFixedPosition;
    var data = this.isPaginateData ? this.dataSource : this.data;
    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)
        }
      });
    })]);
    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.tableWidth, "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
      }
    })])]);
    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,
      handleRowMounted: this.handleRowMounted,
      renderExpandedRow: this.renderExpandedRow
    }, pick(this.$props, extendTableProps));

    var on = this.getListenser();
    var tableContent = h("div", {
      "ref": "tableContentRef",
      "class": this.tableBaseClass.content,
      "style": this.tableContentStyles,
      "on": {
        "scroll": this.onInnerScroll
      }
    }, [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
      }
    }), h(TBody, helper([{
      "scopedSlots": this.$scopedSlots
    }, {
      "props": tableBodyProps
    }, {}, {
      "on": on
    }])), h(TFoot, {
      "scopedSlots": this.$scopedSlots,
      "attrs": {
        "isFixedHeader": this.isFixedHeader,
        "rowAndColFixedPosition": rowAndColFixedPosition,
        "footData": this.footData,
        "columns": this.columns,
        "rowAttributes": this.rowAttributes,
        "rowClassName": this.rowClassName
      }
    })])]);
    var customLoadingText = this.renderTNode("loading");
    var loadingContent = this.loading ? h(Loading, helper([{
      "attrs": {
        "loading": !!(this.loading || customLoadingText),
        "text": customLoadingText ? function () {
          return customLoadingText;
        } : void 0,
        "showOverlay": true
      }
    }, {
      "props": this.loadingProps
    }]), [tableContent]) : tableContent;
    var topContent = this.renderTNode("topContent");
    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), loadingContent, this.showRightDivider && h("div", {
      "class": this.tableBaseClass.scrollbarDivider,
      "style": {
        right: "".concat(this.scrollbarWidth, "px"),
        height: "".concat(this.tableContentRef.offsetHeight, "px")
      }
    }), this.renderPagination(h)]);
  }
});

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