"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var VirtualMenuList_exports = {};
__export(VirtualMenuList_exports, {
  VirtualMenuList: () => VirtualMenuList,
  VirtualRow: () => VirtualRow
});
module.exports = __toCommonJS(VirtualMenuList_exports);
var import_react = __toESM(require("react"));
var import_react_select = require("react-select");
var import_react_window = require("react-window");
const VirtualRow = (0, import_react.memo)(({ style, children }) => /* @__PURE__ */ import_react.default.createElement("div", { style }, children));
function VirtualMenuList(props) {
  const { children, options, maxHeight, getValue, getStyles, selectProps } = props;
  const { noOptionsMessage, rowHeight = 0 } = selectProps;
  const listRef = (0, import_react.useRef)();
  const [value] = getValue();
  const initialOffset = options.indexOf(value) * rowHeight;
  const childrenLength = Array.isArray(children) ? children.length : 0;
  const minHeight = Math.min(maxHeight, rowHeight * childrenLength);
  const menuStyle = getStyles("menuList", props);
  const focusedIndex = (0, import_react.useMemo)(
    () => Array.isArray(children) ? Math.max(
      children.findIndex(
        (child) => import_react.default.isValidElement(child) && child.props.isFocused
      ),
      0
    ) : 0,
    [children]
  );
  (0, import_react.useEffect)(() => {
    var _a;
    (_a = listRef.current) == null ? void 0 : _a.scrollToItem(focusedIndex);
  }, [focusedIndex]);
  if (!children || !Array.isArray(children))
    return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
  if (childrenLength === 0 && noOptionsMessage) {
    return /* @__PURE__ */ import_react.default.createElement(import_react_select.components.NoOptionsMessage, { ...{ ...props, innerProps: {} } });
  }
  children.length && children.forEach((node) => {
    if (!node || !import_react.default.isValidElement(node))
      return;
    delete node.props.innerProps.onMouseMove;
    delete node.props.innerProps.onMouseOver;
  });
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: { ...menuStyle, maxHeight: "auto" },
      onWheelCapture: (e) => (
        /*
          This event causes issues with react-window.
          react-select logic is based on whether the bottom/top of the list has been reached
          but with virtual lists it just does not work and prevents scrolling…
        */
        e.stopPropagation()
      )
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_react_window.FixedSizeList,
      {
        ref: listRef,
        width: "100%",
        height: minHeight,
        overscanCount: 50,
        itemCount: childrenLength,
        itemSize: rowHeight,
        initialScrollOffset: initialOffset
      },
      ({ index, style }) => /* @__PURE__ */ import_react.default.createElement(VirtualRow, { style }, children[index])
    )
  );
}
//# sourceMappingURL=VirtualMenuList.js.map
