/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

var getDomWidth = function getDomWidth(dom) {
  return (dom === null || dom === void 0 ? void 0 : dom.offsetWidth) || 0;
};
var tabBase = {
  calcScrollLeft: function calcScrollLeft(elements, scrollLeft) {
    var container = elements.navsContainer;
    var wrap = elements.navsWrap;
    var rightOperations = elements.rightOperations;
    var rightOperationsZoneWidth = getDomWidth(rightOperations);
    if (!wrap || !container) return scrollLeft;
    var containerWidth = getDomWidth(container);
    var wrapWidth = getDomWidth(wrap);
    if (wrapWidth <= containerWidth) {
      return 0;
    }
    if (scrollLeft + containerWidth - rightOperationsZoneWidth > wrapWidth) return wrapWidth + rightOperationsZoneWidth - containerWidth;
    return scrollLeft;
  },
  calculateCanToLeft: function calculateCanToLeft(depElement, scrollLeft, placement) {
    if (["left", "right"].includes(placement.toLowerCase())) return false;
    var container = depElement.navsContainer,
      wrap = depElement.navsWrap,
      leftOperations = depElement.leftOperations,
      toLeftBtn = depElement.toLeftBtn;
    if (!wrap || !container) return false;
    var leftOperationsZoneWidth = getDomWidth(leftOperations);
    var leftIconWidth = getDomWidth(toLeftBtn);
    return scrollLeft + Math.round(leftOperationsZoneWidth - leftIconWidth) > 0;
  },
  calculateCanToRight: function calculateCanToRight(depElement, scrollLeft, placement) {
    if (["left", "right"].includes(placement.toLowerCase())) return false;
    var container = depElement.navsContainer,
      wrap = depElement.navsWrap,
      rightOperations = depElement.rightOperations,
      toRightBtn = depElement.toRightBtn;
    if (!wrap || !container) return false;
    var rightOperationsZoneWidth = getDomWidth(rightOperations);
    var rightIconWidth = getDomWidth(toRightBtn);
    return scrollLeft + getDomWidth(container) - (rightOperationsZoneWidth - rightIconWidth) - getDomWidth(wrap) < -1;
  },
  moveActiveTabIntoView: function moveActiveTabIntoView(depElement, scrollLeft) {
    var activeTab = depElement.activeTab,
      container = depElement.navsContainer,
      navsWrap = depElement.navsWrap,
      leftOperations = depElement.leftOperations,
      toLeftBtn = depElement.toLeftBtn,
      rightOperations = depElement.rightOperations,
      toRightBtn = depElement.toRightBtn;
    if (!activeTab) return scrollLeft;
    var totalWidthBeforeActiveTab = activeTab.offsetLeft;
    if (!container) return scrollLeft;
    var _getLeftCoverWidth = function _getLeftCoverWidth() {
      var leftOperationsZoneWidth = getDomWidth(leftOperations);
      var leftIconWidth = getDomWidth(toLeftBtn);
      if (totalWidthBeforeActiveTab === 0) {
        return leftOperationsZoneWidth - leftIconWidth;
      }
      return leftOperationsZoneWidth;
    };
    var leftCoverWidth = _getLeftCoverWidth();
    var isCurrentTabHiddenInLeftZone = scrollLeft + leftCoverWidth > totalWidthBeforeActiveTab;
    if (isCurrentTabHiddenInLeftZone) return totalWidthBeforeActiveTab - leftCoverWidth;
    var activeTabWidth = activeTab.offsetWidth;
    if (!container || !navsWrap) return scrollLeft;
    var containerWidth = getDomWidth(container);
    var _getRightCoverWidth = function _getRightCoverWidth() {
      var rightOperationsZoneWidth = getDomWidth(rightOperations);
      var rightIconWidth = getDomWidth(toRightBtn);
      var wrapWidth = getDomWidth(navsWrap);
      if (Math.abs(totalWidthBeforeActiveTab + activeTabWidth - wrapWidth) < 1) {
        return rightOperationsZoneWidth - rightIconWidth;
      }
      return rightOperationsZoneWidth;
    };
    var rightCoverWidth = _getRightCoverWidth();
    var isHiddenInRightZone = scrollLeft + containerWidth - rightCoverWidth < totalWidthBeforeActiveTab + activeTabWidth;
    if (isHiddenInRightZone) return totalWidthBeforeActiveTab + activeTabWidth - containerWidth + rightCoverWidth;
    return scrollLeft;
  },
  scrollToLeft: function scrollToLeft(depElement, scrollLeft) {
    var container = depElement.navsContainer,
      leftOperations = depElement.leftOperations,
      toLeftBtn = depElement.toLeftBtn;
    if (!container) return 0;
    var leftOperationsZoneWidth = getDomWidth(leftOperations);
    var leftIconWidth = getDomWidth(toLeftBtn);
    var containerWidth = getDomWidth(container);
    return Math.max(-(leftOperationsZoneWidth - leftIconWidth), scrollLeft - containerWidth);
  },
  scrollToRight: function scrollToRight(depElement, scrollLeft) {
    var container = depElement.navsContainer,
      wrap = depElement.navsWrap,
      rightOperations = depElement.rightOperations,
      toRightBtn = depElement.toRightBtn;
    var rightOperationsZoneWidth = getDomWidth(rightOperations);
    var rightIconWidth = getDomWidth(toRightBtn);
    var containerWidth = getDomWidth(container);
    var wrapWidth = getDomWidth(wrap);
    return Math.min(scrollLeft + containerWidth - rightOperationsZoneWidth - rightIconWidth, wrapWidth - containerWidth + rightOperationsZoneWidth - rightIconWidth);
  }
};

export { tabBase as default };
//# sourceMappingURL=base.mjs.map
