/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { toRefs, ref, reactive, computed, watch, onMounted, onBeforeMount } from '@vue/composition-api';
import get from 'lodash/get';
import '../../_common/js/log/index.js';
import getScrollbarWidth from '../../_common/js/utils/getScrollbarWidth.js';
import { on, off } from '../../utils/dom.js';
import log from '../../_common/js/log/log.js';
import 'vue';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.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; }
function getColumnFixedStyles(col, index, rowAndColFixedPosition, tableColFixedClasses) {
  var _thClasses;

  var fixedPos = rowAndColFixedPosition === null || rowAndColFixedPosition === void 0 ? void 0 : rowAndColFixedPosition.get(col.colKey || index);
  if (!fixedPos) return {};
  var thClasses = (_thClasses = {}, _defineProperty(_thClasses, tableColFixedClasses.left, col.fixed === "left"), _defineProperty(_thClasses, tableColFixedClasses.right, col.fixed === "right"), _defineProperty(_thClasses, tableColFixedClasses.lastLeft, col.fixed === "left" && fixedPos.lastLeftFixedCol), _defineProperty(_thClasses, tableColFixedClasses.firstRight, col.fixed === "right" && fixedPos.firstRightFixedCol), _thClasses);
  var thStyles = {
    left: col.fixed === "left" ? "".concat(fixedPos.left, "px") : void 0,
    right: col.fixed === "right" ? "".concat(fixedPos.right, "px") : void 0
  };
  return {
    style: thStyles,
    classes: thClasses
  };
}
function getRowFixedStyles(rowId, rowIndex, rowLength, fixedRows, rowAndColFixedPosition, tableRowFixedClasses) {
  var _rowClasses;

  if (!fixedRows || !fixedRows.length) return {
    style: void 0,
    classes: void 0
  };
  var fixedTop = rowIndex < fixedRows[0];
  var fixedBottom = rowIndex > rowLength - 1 - fixedRows[1];
  var firstFixedBottomRow = rowLength - fixedRows[1];
  var fixedPos = (rowAndColFixedPosition === null || rowAndColFixedPosition === void 0 ? void 0 : rowAndColFixedPosition.get(rowId)) || {};
  var rowClasses = (_rowClasses = {}, _defineProperty(_rowClasses, tableRowFixedClasses.top, fixedTop), _defineProperty(_rowClasses, tableRowFixedClasses.bottom, fixedBottom), _defineProperty(_rowClasses, tableRowFixedClasses.firstBottom, rowIndex === firstFixedBottomRow), _defineProperty(_rowClasses, tableRowFixedClasses.withoutBorderBottom, rowIndex === firstFixedBottomRow - 1), _rowClasses);
  var rowStyles = {
    top: fixedTop ? "".concat(fixedPos.top, "px") : void 0,
    bottom: fixedBottom ? "".concat(fixedPos.bottom, "px") : void 0
  };
  return {
    style: rowStyles,
    classes: rowClasses
  };
}
function useFixed(props, context) {
  var _toRefs = toRefs(props),
      data = _toRefs.data,
      columns = _toRefs.columns,
      tableLayout = _toRefs.tableLayout,
      tableContentWidth = _toRefs.tableContentWidth,
      fixedRows = _toRefs.fixedRows,
      firstFullRow = _toRefs.firstFullRow,
      lastFullRow = _toRefs.lastFullRow,
      maxHeight = _toRefs.maxHeight,
      headerAffixedTop = _toRefs.headerAffixedTop,
      footerAffixedBottom = _toRefs.footerAffixedBottom,
      bordered = _toRefs.bordered;

  var tableContentRef = ref();
  var isFixedHeader = ref(false);
  var isWidthOverflow = ref(false);
  var affixHeaderRef = ref();
  var affixFooterRef = ref();
  var tableElmRef = ref();
  var showAffixHeader = ref(true);
  var showAffixFooter = ref(true);
  var scrollbarWidth = ref(6);
  var rowAndColFixedPosition = ref( /* @__PURE__ */new Map());
  var showColumnShadow = reactive({
    left: false,
    right: false
  });
  var virtualScrollHeaderPos = ref({
    left: 0,
    top: 0
  });
  var tableWidth = ref(0);
  var tableElmWidth = ref(0);
  var thWidthList = ref({});
  var isFixedColumn = ref(false);
  var isFixedRightColumn = ref(false);
  var isFixedLeftColumn = ref(false);
  var notNeedThWidthList = computed(function () {
    var _props$scroll;

    return !(props.headerAffixedTop || props.footerAffixedBottom || ((_props$scroll = props.scroll) === null || _props$scroll === void 0 ? void 0 : _props$scroll.type) === "virtual");
  });

  function setUseFixedTableElmRef(val) {
    tableElmRef.value = val;
  }

  function getColumnMap(columns2) {
    var map = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /* @__PURE__ */new Map();
    var levelNodes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
    var level = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
    var parent = arguments.length > 4 ? arguments[4] : undefined;

    for (var i = 0, len = columns2.length; i < len; i++) {
      var _col$children;

      var col = columns2[i];

      if (["left", "right"].includes(col.fixed)) {
        isFixedColumn.value = true;
      }

      if (col.fixed === "right") {
        isFixedRightColumn.value = true;
      }

      if (col.fixed === "left") {
        isFixedLeftColumn.value = true;
      }

      var key = col.colKey || i;
      var columnInfo = {
        col: col,
        parent: parent,
        index: i
      };
      map.set(key, columnInfo);

      if ((_col$children = col.children) !== null && _col$children !== void 0 && _col$children.length) {
        getColumnMap(col.children, map, levelNodes, level + 1, columnInfo);
      }

      if (levelNodes[level]) {
        levelNodes[level].push(columnInfo);
      } else {
        levelNodes[level] = [columnInfo];
      }
    }

    return {
      newColumnsMap: map,
      levelNodes: levelNodes
    };
  }

  var setFixedLeftPos = function setFixedLeftPos(columns2, initialColumnMap) {
    var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

    for (var i = 0, len = columns2.length; i < len; i++) {
      var _col$children2;

      var col = columns2[i];
      if (col.fixed === "right") return;
      var colInfo = initialColumnMap.get(col.colKey || i);
      var lastColIndex = i - 1;

      while (lastColIndex >= 0 && columns2[lastColIndex].fixed !== "left") {
        lastColIndex -= 1;
      }

      var lastCol = columns2[lastColIndex];
      var defaultWidth = i === 0 ? (parent === null || parent === void 0 ? void 0 : parent.left) || 0 : 0;
      var lastColInfo = initialColumnMap.get((lastCol === null || lastCol === void 0 ? void 0 : lastCol.colKey) || i - 1);
      colInfo.left = ((lastColInfo === null || lastColInfo === void 0 ? void 0 : lastColInfo.left) || defaultWidth) + ((lastColInfo === null || lastColInfo === void 0 ? void 0 : lastColInfo.width) || 0);

      if ((_col$children2 = col.children) !== null && _col$children2 !== void 0 && _col$children2.length) {
        setFixedLeftPos(col.children, initialColumnMap, colInfo);
      }
    }
  };

  var setFixedRightPos = function setFixedRightPos(columns2, initialColumnMap) {
    var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

    for (var i = columns2.length - 1; i >= 0; i--) {
      var _col$children3;

      var col = columns2[i];
      if (col.fixed === "left") return;
      var colInfo = initialColumnMap.get(col.colKey || i);
      var lastColIndex = i + 1;

      while (lastColIndex < columns2.length && columns2[lastColIndex].fixed !== "right") {
        lastColIndex += 1;
      }

      var lastCol = columns2[lastColIndex];
      var defaultWidth = i === columns2.length - 1 ? (parent === null || parent === void 0 ? void 0 : parent.right) || 0 : 0;
      var lastColInfo = initialColumnMap.get((lastCol === null || lastCol === void 0 ? void 0 : lastCol.colKey) || i + 1);
      colInfo.right = ((lastColInfo === null || lastColInfo === void 0 ? void 0 : lastColInfo.right) || defaultWidth) + ((lastColInfo === null || lastColInfo === void 0 ? void 0 : lastColInfo.width) || 0);

      if ((_col$children3 = col.children) !== null && _col$children3 !== void 0 && _col$children3.length) {
        setFixedRightPos(col.children, initialColumnMap, colInfo);
      }
    }
  };

  var setFixedColPosition = function setFixedColPosition(trList, initialColumnMap) {
    if (!trList) return;

    for (var i = 0, len = trList.length; i < len; i++) {
      var thList = trList[i].children;

      for (var j = 0, thLen = thList.length; j < thLen; j++) {
        var _obj$col;

        var th = thList[j];
        var colKey = th.dataset.colkey;

        if (!colKey) {
          log.warn("TDesign Table", "".concat(th.innerText, " missing colKey. colKey is required for fixed column feature."));
        }

        var obj = initialColumnMap.get(colKey || j);

        if (obj !== null && obj !== void 0 && (_obj$col = obj.col) !== null && _obj$col !== void 0 && _obj$col.fixed) {
          initialColumnMap.set(colKey, _objectSpread(_objectSpread({}, obj), {}, {
            width: th.getBoundingClientRect().width
          }));
        }
      }
    }

    setFixedLeftPos(columns.value, initialColumnMap);
    setFixedRightPos(columns.value, initialColumnMap);
  };

  var setFixedRowPosition = function setFixedRowPosition(trList, initialColumnMap, thead, tfoot) {
    var _ref = fixedRows.value || [],
        _ref2 = _slicedToArray(_ref, 2),
        fixedTopRows = _ref2[0],
        fixedBottomRows = _ref2[1];

    var data2 = props.data,
        _props$rowKey = props.rowKey,
        rowKey = _props$rowKey === void 0 ? "id" : _props$rowKey;

    for (var i = 0; i < fixedTopRows; i++) {
      var tr = trList[i];
      var rowId = get(data2[i], rowKey);
      var thisRowInfo = initialColumnMap.get(rowId) || {};
      var lastRowId = get(data2[i - 1], rowKey);
      var lastRowInfo = initialColumnMap.get(lastRowId) || {};
      var defaultBottom = 0;

      if (i === 0) {
        defaultBottom = (thead === null || thead === void 0 ? void 0 : thead.getBoundingClientRect().height) || 0;
      }

      thisRowInfo.top = (lastRowInfo.top || defaultBottom) + (lastRowInfo.height || 0);
      initialColumnMap.set(rowId, _objectSpread(_objectSpread({}, thisRowInfo), {}, {
        height: tr.getBoundingClientRect().height
      }));
    }

    for (var _i = data2.length - 1; _i >= data2.length - fixedBottomRows; _i--) {
      var _tr = trList[_i];

      var _rowId = get(data2[_i], rowKey);

      var _thisRowInfo = initialColumnMap.get(_rowId) || {};

      var _lastRowId = get(data2[_i + 1], rowKey);

      var _lastRowInfo = initialColumnMap.get(_lastRowId) || {};

      var _defaultBottom = 0;

      if (_i === data2.length - 1) {
        _defaultBottom = (tfoot === null || tfoot === void 0 ? void 0 : tfoot.getBoundingClientRect().height) || 0;
      }

      _thisRowInfo.bottom = (_lastRowInfo.bottom || _defaultBottom) + (_lastRowInfo.height || 0);
      initialColumnMap.set(_rowId, _objectSpread(_objectSpread({}, _thisRowInfo), {}, {
        height: _tr.getBoundingClientRect().height
      }));
    }
  };

  var updateRowAndColFixedPosition = function updateRowAndColFixedPosition(tableContentElm, initialColumnMap) {
    rowAndColFixedPosition.value.clear();
    var thead = tableContentElm.querySelector("thead");
    thead && setFixedColPosition(thead.children, initialColumnMap);
    var tbody = tableContentElm.querySelector("tbody");
    var tfoot = tableContentElm.querySelector("tfoot");
    tbody && setFixedRowPosition(tbody.children, initialColumnMap, thead, tfoot);
    rowAndColFixedPosition.value = initialColumnMap;
  };

  var shadowLastScrollLeft;

  var updateColumnFixedShadow = function updateColumnFixedShadow(target) {
    if (!isFixedColumn.value) return;
    var scrollLeft = target.scrollLeft;
    if (shadowLastScrollLeft === scrollLeft) return;
    shadowLastScrollLeft = scrollLeft;
    var isShowRight = target.clientWidth + scrollLeft < target.scrollWidth;
    showColumnShadow.left = scrollLeft > 0;
    showColumnShadow.right = isShowRight;
  };

  var lastScrollLeft = -1;

  var updateHeaderScroll = function updateHeaderScroll(target) {
    if (notNeedThWidthList.value) return;

    if (!target) {
      lastScrollLeft = -1;
    }

    var newTarget = target || tableContentRef.value;
    if (notNeedThWidthList.value || !newTarget) return;
    var left = newTarget.scrollLeft;
    if (lastScrollLeft === left) return;

    if (affixHeaderRef.value) {
      lastScrollLeft = left;
      affixHeaderRef.value.scrollLeft = left;
    }

    if (affixFooterRef.value) {
      lastScrollLeft = left;
      affixFooterRef.value.scrollLeft = left;
    }
  };

  var lastFootScrollLeft = -1;

  var updateScrollPositionByFootScrollbar = function updateScrollPositionByFootScrollbar() {
    if (notNeedThWidthList.value) return;
    var target = affixFooterRef.value;
    var left = target.scrollLeft;
    if (lastFootScrollLeft === left) return;

    if (affixHeaderRef.value) {
      lastFootScrollLeft = left;
      affixHeaderRef.value.scrollLeft = left;
    }

    if (tableContentRef.value) {
      lastFootScrollLeft = left;
      tableContentRef.value.scrollLeft = left;
    }
  };

  var onTableContentScroll = function onTableContentScroll(params) {
    var target = tableContentRef.value;
    updateColumnFixedShadow(target);

    if ((params === null || params === void 0 ? void 0 : params.trigger) === "tfoot") {
      updateScrollPositionByFootScrollbar();
    } else {
      updateHeaderScroll(target);
    }

    onContentScrollEvent(params.e);
  };

  var onContentScrollEvent = function onContentScrollEvent(e) {
    var _props$onScrollX, _props$onScrollY, _props$onScroll;

    (_props$onScrollX = props.onScrollX) === null || _props$onScrollX === void 0 ? void 0 : _props$onScrollX.call(props, {
      e: e
    });
    context.emit("scroll-x", {
      e: e
    });
    (_props$onScrollY = props.onScrollY) === null || _props$onScrollY === void 0 ? void 0 : _props$onScrollY.call(props, {
      e: e
    });
    context.emit("scroll-y", {
      e: e
    });
    (_props$onScroll = props.onScroll) === null || _props$onScroll === void 0 ? void 0 : _props$onScroll.call(props, {
      e: e
    });
    context.emit("scroll", {
      e: e
    });
  };

  var setIsLastOrFirstFixedCol = function setIsLastOrFirstFixedCol(levelNodes) {
    for (var t = 0; t < levelNodes.length; t++) {
      var nodes = levelNodes[t];

      for (var i = 0, len = nodes.length; i < len; i++) {
        var colMapInfo = nodes[i];
        var nextColMapInfo = nodes[i + 1];
        var parent = colMapInfo.parent;
        var isParentLastLeftFixedCol = !parent || (parent === null || parent === void 0 ? void 0 : parent.lastLeftFixedCol);

        if (isParentLastLeftFixedCol && colMapInfo.col.fixed === "left" && (nextColMapInfo === null || nextColMapInfo === void 0 ? void 0 : nextColMapInfo.col.fixed) !== "left") {
          colMapInfo.lastLeftFixedCol = true;
        }

        var lastColMapInfo = nodes[i - 1];
        var isParentFirstRightFixedCol = !parent || (parent === null || parent === void 0 ? void 0 : parent.firstRightFixedCol);

        if (isParentFirstRightFixedCol && colMapInfo.col.fixed === "right" && (lastColMapInfo === null || lastColMapInfo === void 0 ? void 0 : lastColMapInfo.col.fixed) !== "right") {
          colMapInfo.firstRightFixedCol = true;
        }
      }
    }
  };

  var updateFixedStatus = function updateFixedStatus() {
    var _getColumnMap = getColumnMap(columns.value),
        newColumnsMap = _getColumnMap.newColumnsMap,
        levelNodes = _getColumnMap.levelNodes;

    setIsLastOrFirstFixedCol(levelNodes);
    var timer = setTimeout(function () {
      var _fixedRows$value;

      if (isFixedColumn.value || (_fixedRows$value = fixedRows.value) !== null && _fixedRows$value !== void 0 && _fixedRows$value.length) {
        updateRowAndColFixedPosition(tableContentRef.value, newColumnsMap);
      }

      clearTimeout(timer);
    }, 0);
    return function () {
      clearTimeout(timer);
    };
  };

  var updateFixedHeader = function updateFixedHeader() {
    var timer = setTimeout(function () {
      if (!tableContentRef.value) return;
      isFixedHeader.value = tableContentRef.value.scrollHeight > tableContentRef.value.clientHeight;
      isWidthOverflow.value = tableContentRef.value.scrollWidth > tableContentRef.value.clientWidth;
      var pos = tableContentRef.value.getBoundingClientRect();
      virtualScrollHeaderPos.value = {
        top: pos.top,
        left: pos.left
      };
      clearTimeout(timer);
    }, 0);
  };

  var updateFixedColumnHandler = function updateFixedColumnHandler() {
    var timer = setTimeout(function () {
      if (isFixedColumn.value) {
        updateColumnFixedShadow(tableContentRef.value);
      }

      clearTimeout(timer);
    }, 0);
  };

  var updateTableWidth = function updateTableWidth() {
    var _tableContentRef$valu, _tableElmRef$value;

    var rect = (_tableContentRef$valu = tableContentRef.value) === null || _tableContentRef$valu === void 0 ? void 0 : _tableContentRef$valu.getBoundingClientRect();
    var reduceWidth = isFixedHeader.value ? scrollbarWidth.value : 0;
    tableWidth.value = rect.width - reduceWidth - (props.bordered ? 1 : 0);
    var elmRect = tableElmRef === null || tableElmRef === void 0 ? void 0 : (_tableElmRef$value = tableElmRef.value) === null || _tableElmRef$value === void 0 ? void 0 : _tableElmRef$value.getBoundingClientRect();
    tableElmWidth.value = elmRect === null || elmRect === void 0 ? void 0 : elmRect.width;
  };

  var updateThWidthList = function updateThWidthList(trList) {
    var widthMap = {};

    for (var i = 0, len = trList.length; i < len; i++) {
      var thList = trList[i].children;

      for (var j = 0, thLen = thList.length; j < thLen; j++) {
        var th = thList[j];
        var colKey = th.dataset.colkey;
        widthMap[colKey] = th.getBoundingClientRect().width;
      }
    }

    thWidthList.value = widthMap;
    updateHeaderScroll();
  };

  var updateThWidthListHandler = function updateThWidthListHandler() {
    if (notNeedThWidthList.value) return;
    var timer = setTimeout(function () {
      updateTableWidth();
      var thead = tableContentRef.value.querySelector("thead");
      updateThWidthList(thead.children);
      clearTimeout(timer);
    }, 0);
  };

  var updateAffixHeaderOrFooter = function updateAffixHeaderOrFooter() {
    var _props$scroll2;

    var pos = tableContentRef.value.getBoundingClientRect();

    if (props.headerAffixedTop || ((_props$scroll2 = props.scroll) === null || _props$scroll2 === void 0 ? void 0 : _props$scroll2.type) === "virtual") {
      var _affixHeaderRef$value;

      var r = ((_affixHeaderRef$value = affixHeaderRef.value) === null || _affixHeaderRef$value === void 0 ? void 0 : _affixHeaderRef$value.offsetHeight) - pos.top < pos.height;
      showAffixHeader.value = r;
    }

    if (props.footerAffixedBottom) {
      var _affixFooterRef$value, _tableContentRef$valu2, _tableContentRef$valu3;

      showAffixFooter.value = pos.top + ((affixFooterRef === null || affixFooterRef === void 0 ? void 0 : (_affixFooterRef$value = affixFooterRef.value) === null || _affixFooterRef$value === void 0 ? void 0 : _affixFooterRef$value.clientHeight) || 48) <= window.innerHeight && -1 * pos.top < (tableContentRef === null || tableContentRef === void 0 ? void 0 : (_tableContentRef$valu2 = tableContentRef.value) === null || _tableContentRef$valu2 === void 0 ? void 0 : (_tableContentRef$valu3 = _tableContentRef$valu2.parentNode) === null || _tableContentRef$valu3 === void 0 ? void 0 : _tableContentRef$valu3.clientHeight);
    }
  };

  var onDocumentScroll = function onDocumentScroll() {
    if (notNeedThWidthList.value) return;
    updateAffixHeaderOrFooter();
  };

  watch([data, columns, bordered, tableLayout, tableContentWidth, isFixedHeader, isWidthOverflow, isFixedColumn, fixedRows, firstFullRow, lastFullRow], updateFixedStatus, {
    immediate: true
  });
  watch([isFixedColumn, columns], updateFixedColumnHandler, {
    immediate: true
  });
  watch([maxHeight, data, columns, bordered], updateFixedHeader, {
    immediate: true
  });
  watch([data, columns, bordered, tableLayout, fixedRows, isFixedHeader, headerAffixedTop, footerAffixedBottom, tableContentWidth], updateThWidthListHandler, {
    immediate: true
  });
  watch([headerAffixedTop, footerAffixedBottom], function (_ref3) {
    var _ref4 = _slicedToArray(_ref3, 2),
        headerAffixedTop2 = _ref4[0],
        footerAffixedBottom2 = _ref4[1];

    if (headerAffixedTop2 || footerAffixedBottom2) {
      on(document, "scroll", onDocumentScroll);
    } else {
      off(document, "scroll", onDocumentScroll);
    }
  });

  var refreshTable = function refreshTable() {
    updateTableWidth();
    updateFixedHeader();

    if (!notNeedThWidthList.value) {
      updateThWidthListHandler();
    }

    if (isFixedColumn.value || isFixedHeader.value) {
      updateFixedStatus();
      updateColumnFixedShadow(tableContentRef.value);
    }
  };

  var onResize = refreshTable;

  var onFootScroll = function onFootScroll(e) {
    onTableContentScroll({
      e: e,
      trigger: "tfoot"
    });
  };

  var onFootMouseEnter = function onFootMouseEnter() {
    on(affixFooterRef.value, "scroll", onFootScroll);
  };

  var onFootMouseLeave = function onFootMouseLeave() {
    off(affixFooterRef.value, "scroll", onFootScroll);
  };

  watch(affixFooterRef, function () {
    if (footerAffixedBottom.value && affixFooterRef.value) {
      on(affixFooterRef.value, "mouseenter", onFootMouseEnter);
      on(affixFooterRef.value, "mouseleave", onFootMouseLeave);
    } else {
      off(affixFooterRef.value, "mouseenter", onFootMouseEnter);
      off(affixFooterRef.value, "mouseleave", onFootMouseLeave);
    }
  });

  var onTableContentMouseEnter = function onTableContentMouseEnter() {
    on(tableContentRef.value, "scroll", onTableContentScroll);
  };

  var onTableContentMouseLeave = function onTableContentMouseLeave() {
    off(tableContentRef.value, "scroll", onTableContentScroll);
  };

  var addTableContentListener = function addTableContentListener() {
    if (!notNeedThWidthList.value && tableContentRef.value || isFixedColumn.value) {
      on(tableContentRef.value, "mouseenter", onTableContentMouseEnter);
      on(tableContentRef.value, "mouseleave", onTableContentMouseLeave);
    }
  };

  var removeTableContentListener = function removeTableContentListener() {
    off(tableContentRef.value, "mouseenter", onTableContentMouseEnter);
    off(tableContentRef.value, "mouseleave", onTableContentMouseLeave);
  };

  watch(tableContentRef, function () {
    addTableContentListener();
  });
  onMounted(function () {
    var scrollWidth = getScrollbarWidth();
    scrollbarWidth.value = scrollWidth;
    var timer = setTimeout(function () {
      updateTableWidth();
      clearTimeout(timer);
      updateAffixHeaderOrFooter();
    });

    if (headerAffixedTop.value || footerAffixedBottom.value) {
      on(document, "scroll", onDocumentScroll);
    } else {
      off(document, "scroll", onDocumentScroll);
    }

    if (isFixedColumn.value || isFixedHeader.value || !notNeedThWidthList.value) {
      on(window, "resize", onResize);
    }

    addTableContentListener();
  });
  onBeforeMount(function () {
    if (isFixedColumn.value || isFixedHeader.value || !notNeedThWidthList.value) {
      off(window, "resize", onResize);
    }

    if (props.headerAffixedTop || props.footerAffixedBottom) {
      off(document, "scroll", onDocumentScroll);
      off(affixFooterRef.value, "mouseenter", onFootMouseEnter);
      off(affixFooterRef.value, "mouseleave", onFootMouseLeave);
    }

    if (!notNeedThWidthList.value) {
      removeTableContentListener();
    }
  });
  return {
    tableWidth: tableWidth,
    tableElmWidth: tableElmWidth,
    thWidthList: thWidthList,
    isFixedHeader: isFixedHeader,
    isWidthOverflow: isWidthOverflow,
    tableContentRef: tableContentRef,
    showAffixHeader: showAffixHeader,
    showAffixFooter: showAffixFooter,
    isFixedColumn: isFixedColumn,
    showColumnShadow: showColumnShadow,
    rowAndColFixedPosition: rowAndColFixedPosition,
    virtualScrollHeaderPos: virtualScrollHeaderPos,
    affixHeaderRef: affixHeaderRef,
    affixFooterRef: affixFooterRef,
    scrollbarWidth: scrollbarWidth,
    refreshTable: refreshTable,
    updateThWidthListHandler: updateThWidthListHandler,
    updateHeaderScroll: updateHeaderScroll,
    onTableContentScroll: onTableContentScroll,
    setUseFixedTableElmRef: setUseFixedTableElmRef
  };
}

export { useFixed as default, getColumnFixedStyles, getRowFixedStyles };
//# sourceMappingURL=useFixed.js.map
