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

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var helper = require('../_chunks/dep-33ee4bce.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var pick = require('lodash/pick');
var table_baseTableProps = require('./base-table-props.js');
var table_hooks_useTableHeader = require('./hooks/useTableHeader.js');
var table_hooks_useFixed = require('./hooks/useFixed.js');
var table_hooks_usePagination = require('./hooks/usePagination.js');
var hooks_useVirtualScroll = require('../hooks/useVirtualScroll.js');
var loading_index = require('../loading/index.js');
var table_tbody = require('./tbody.js');
var hooks_tnode = require('../hooks/tnode.js');
var table_hooks_useStyle = require('./hooks/useStyle.js');
var table_hooks_useClassName = require('./hooks/useClassName.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
var affix_index = require('../affix/index.js');
var table_tr = require('./tr.js');
var table_thead = require('./thead.js');
var table_tfoot = require('./tfoot.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isString');
require('lodash/isFunction');
require('./hooks/useMultiHeader.js');
require('lodash/get');
require('../_common/js/log/log.js');
require('../_common/js/utils/getScrollbarWidth.js');
require('../utils/dom.js');
require('vue');
require('raf');
require('../utils/easing.js');
require('../pagination/index.js');
require('../pagination/pagination.js');
require('@babel/runtime/helpers/typeof');
require('tdesign-icons-vue');
require('../config.js');
require('../utils/mixins.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../input-number/index.js');
require('../input-number/input-number.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/regenerator');
require('../button/index.js');
require('../button/button.js');
require('../utils/classnames.js');
require('../button/props.js');
require('../utils/render-tnode.js');
require('lodash/isObject');
require('../utils/ripple.js');
require('../_common/js/utils/set-style.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../loading/plugin.js');
require('../input/index.js');
require('../input/addon.js');
require('../input/input.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/helper.js');
require('../utils/event.js');
require('../input/props.js');
require('../input/input-group.js');
require('../utils/map-props.js');
require('../input-number/props.js');
require('../select/index.js');
require('../select/select.js');
require('lodash/debounce');
require('lodash/set');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../popup/props.js');
require('../popup/container.js');
require('../tag/index.js');
require('../tag/tag.js');
require('../tag/props.js');
require('../tag/check-tag.js');
require('../tag/check-tag-props.js');
require('../common-components/fake-arrow.js');
require('../select/option.js');
require('../select/option-props.js');
require('../checkbox/index.js');
require('../checkbox/group.js');
require('lodash/intersection');
require('../checkbox/checkbox.js');
require('../checkbox/props.js');
require('../checkbox/checkbox-group-props.js');
require('../select/props.js');
require('../select/optionGroup.js');
require('../select/option-group-props.js');
require('../pagination/props.js');
require('lodash/isEmpty');
require('../hooks/render-tnode.js');
require('../hooks/useCommonClassName.js');
require('lodash/cloneDeep');
require('../affix/affix.js');
require('../affix/props.js');
require('lodash/upperFirst');
require('./utils.js');
require('./ellipsis.js');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var pick__default = /*#__PURE__*/_interopDefaultLegacy(pick);

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__default["default"](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 = table_tr.ROW_LISTENERS.map(function (t) {
  return "row-".concat(t);
}).concat(BASE_TABLE_EVENTS);
var _BaseTable = VueCompositionAPI.defineComponent({
  name: "TBaseTable",
  props: _objectSpread(_objectSpread({}, table_baseTableProps["default"]), {}, {
    renderExpandedRow: Function
  }),
  setup: function setup(props2, context) {
    var _props2$scroll2;

    var renderTNode = hooks_tnode.useTNodeJSX();
    var tableRef = VueCompositionAPI.ref();
    var tableElmRef = VueCompositionAPI.ref();

    var _useClassName = table_hooks_useClassName["default"](),
        virtualScrollClasses = _useClassName.virtualScrollClasses,
        tableLayoutClasses = _useClassName.tableLayoutClasses,
        tableBaseClass = _useClassName.tableBaseClass,
        tableColFixedClasses = _useClassName.tableColFixedClasses;

    var _useStyle = table_hooks_useStyle["default"](props2),
        tableClasses = _useStyle.tableClasses,
        tableContentStyles = _useStyle.tableContentStyles,
        tableElementStyles = _useStyle.tableElementStyles;

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

    var _useFixed = table_hooks_useFixed["default"](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 = table_hooks_useTableHeader["default"](props2),
        isMultipleHeader = _useTableHeader.isMultipleHeader,
        spansAndLeafNodes = _useTableHeader.spansAndLeafNodes,
        thList = _useTableHeader.thList;

    var _usePagination = table_hooks_usePagination["default"](props2, context),
        dataSource = _usePagination.dataSource,
        isPaginateData = _usePagination.isPaginateData,
        renderPagination = _usePagination.renderPagination;

    var dynamicBaseTableClasses = VueCompositionAPI.computed(function () {
      var _ref;

      return [tableClasses.value, (_ref = {}, _defineProperty__default["default"](_ref, tableBaseClass.headerFixed, isFixedHeader.value), _defineProperty__default["default"](_ref, tableBaseClass.columnFixed, isFixedColumn.value), _defineProperty__default["default"](_ref, tableBaseClass.widthOverflow, isWidthOverflow.value), _defineProperty__default["default"](_ref, tableBaseClass.multipleHeader, isMultipleHeader.value), _defineProperty__default["default"](_ref, tableColFixedClasses.leftShadow, showColumnShadow.left), _defineProperty__default["default"](_ref, tableColFixedClasses.rightShadow, showColumnShadow.right), _ref)];
    });
    var tableElmClasses = VueCompositionAPI.computed(function () {
      return [[tableLayoutClasses[props2.tableLayout]], _defineProperty__default["default"]({}, tableBaseClass.fullHeight, props2.height)];
    });
    var isVirtual = VueCompositionAPI.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 = VueCompositionAPI.computed(function () {
      return props2.bordered && isFixedHeader.value && (isMultipleHeader.value && isWidthOverflow.value || !isMultipleHeader.value);
    });

    var onFixedChange = function onFixedChange() {
      VueCompositionAPI.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 = VueCompositionAPI.toRefs(props2),
        data = _toRefs.data;

    var _ref4 = type === "virtual" ? hooks_useVirtualScroll["default"]({
      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;

    VueCompositionAPI.provide("tableContentRef", tableContentRef);
    VueCompositionAPI.provide("rowHeightRef", VueCompositionAPI.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: table_hooks_useStyle.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__default["default"]({}, this.tableBaseClass.affixedHeaderElm, this.headerAffixedTop || this.isVirtual)
    }, [h("table", {
      "class": this.tableElmClasses,
      "style": _objectSpread(_objectSpread({}, this.tableElementStyles), {}, {
        width: "".concat(this.tableWidth, "px")
      })
    }, [colgroup, h(table_thead["default"], {
      "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__default["default"](this.$props, table_tbody.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(table_thead["default"], {
      "scopedSlots": this.$scopedSlots,
      "attrs": {
        "isFixedHeader": this.isFixedHeader,
        "rowAndColFixedPosition": this.rowAndColFixedPosition,
        "isMultipleHeader": this.isMultipleHeader,
        "bordered": this.bordered,
        "spansAndLeafNodes": this.spansAndLeafNodes,
        "thList": this.thList
      }
    }), h(table_tbody["default"], helper.helper([{
      "scopedSlots": this.$scopedSlots
    }, {
      "props": tableBodyProps
    }, {}, {
      "on": on
    }])), h(table_tfoot["default"], {
      "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_index.Loading, helper.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_index.Affix, helper.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)]);
  }
});

exports.BASE_TABLE_ALL_EVENTS = BASE_TABLE_ALL_EVENTS;
exports.BASE_TABLE_EVENTS = BASE_TABLE_EVENTS;
exports["default"] = _BaseTable;
//# sourceMappingURL=base-table.js.map
