"use strict";
const React = require("react");
const index$1 = require("../../../icon/react-icon/IconDown/index.js");
const index$2 = require("../../Dropdown/index.js");
const index = require("../../Menu/index.js");
const iconHover = require("../../_class/icon-hover.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
function DropdownIcon(props) {
  var prefixCls = props.prefixCls, currentOffset = props.currentOffset, headerSize = props.headerSize, headerWrapperSize = props.headerWrapperSize, getTitleRef = props.getTitleRef, paneChildren = props.paneChildren, direction = props.direction;
  var paneKeys = paneChildren.map(function(child) {
    return child.key;
  });
  var size = direction === "vertical" ? headerSize.height : headerSize.width;
  var wrapperSize = direction === "vertical" ? headerWrapperSize.height : headerWrapperSize.width;
  var tabSizes = React.useMemo(function() {
    var map = {};
    var wrapperRect = headerWrapperSize.domRect;
    paneKeys.map(function(key) {
      var titleDom = getTitleRef(key);
      if (!titleDom)
        return;
      var rect = titleDom.getBoundingClientRect();
      map[key] = {
        left: rect.left - wrapperRect.left,
        right: rect.left - wrapperRect.left + rect.width,
        top: rect.top - wrapperRect.top,
        bottom: rect.top - wrapperRect.top + rect.height
      };
    });
    return map;
  }, [paneKeys.join(","), size, wrapperSize]);
  var rangeIndex = React.useMemo(function() {
    var start = -1;
    var end = -1;
    for (var key in tabSizes) {
      var _a = tabSizes[key], left = _a.left, right = _a.right;
      if (left >= currentOffset && right - currentOffset <= wrapperSize && start === -1) {
        start = paneKeys.indexOf(key);
        end = start;
      }
      if (left >= currentOffset && right - currentOffset > wrapperSize) {
        end = paneKeys.indexOf(key);
        break;
      }
    }
    return [start, end];
  }, [tabSizes, paneKeys.join(","), currentOffset]);
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$2, {
    trigger: "click",
    droplist: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index, {
      onClickMenuItem: props.onClickTab,
      children: paneChildren.map(function(child, index$12) {
        if (index$12 < rangeIndex[0] || index$12 >= rangeIndex[1]) {
          return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index.Item, {
            disabled: child.disabled,
            children: child.props.title
          }, child.key);
        }
      })
    }),
    children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(iconHover, {
      role: "button",
      "aria-label": "expand tabs",
      prefix: prefixCls + "-dropdown",
      className: prefixCls + "-dropdown-icon",
      children: /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(index$1, {})
    })
  });
}
module.exports = DropdownIcon;
//# sourceMappingURL=dropdown-icon.js.map
