import i from "./index-extends.js";
import E from "./index-objectWithoutPropertiesLoose.js";
import * as l from "react";
import { isFragment as G } from "react-is";
import o from "./index-_virtual16.js";
import { clsx as H } from "./index-clsx.js";
import { useRtl as W } from "./index-RtlProvider.js";
import h from "./index-styled.js";
import { getMenuUtilityClass as $ } from "./index-menuClasses.js";
import { jsx as I } from "react/jsx-runtime";
import { useDefaultProps as q } from "./index-DefaultPropsProvider.js";
import L from "./index-useSlotProps.js";
import B from "./index-composeClasses.js";
import J, { PopoverPaper as Q } from "./index-Popover2.js";
import X from "./index-rootShouldForwardProp.js";
import Y from "./index-MenuList.js";
import Z from "./index-HTMLElementType.js";
const oo = ["onEntering"], eo = ["autoFocus", "children", "className", "disableAutoFocusItem", "MenuListProps", "onClose", "open", "PaperProps", "PopoverClasses", "transitionDuration", "TransitionProps", "variant", "slots", "slotProps"], to = {
  vertical: "top",
  horizontal: "right"
}, ro = {
  vertical: "top",
  horizontal: "left"
}, so = (r) => {
  const {
    classes: t
  } = r;
  return B({
    root: ["root"],
    paper: ["paper"],
    list: ["list"]
  }, $, t);
}, no = h(J, {
  shouldForwardProp: (r) => X(r) || r === "classes",
  name: "MuiMenu",
  slot: "Root",
  overridesResolver: (r, t) => t.root
})({}), ao = h(Q, {
  name: "MuiMenu",
  slot: "Paper",
  overridesResolver: (r, t) => t.paper
})({
  // specZ: The maximum height of a simple menu should be one or more rows less than the view
  // height. This ensures a tappable area outside of the simple menu with which to dismiss
  // the menu.
  maxHeight: "calc(100% - 96px)",
  // Add iOS momentum scrolling for iOS < 13.0
  WebkitOverflowScrolling: "touch"
}), po = h(Y, {
  name: "MuiMenu",
  slot: "List",
  overridesResolver: (r, t) => t.list
})({
  // We disable the focus ring for mouse, touch and keyboard users.
  outline: 0
}), io = /* @__PURE__ */ l.forwardRef(function(t, y) {
  var O, R;
  const s = q({
    props: t,
    name: "MuiMenu"
  }), {
    autoFocus: c = !0,
    children: g,
    className: D,
    disableAutoFocusItem: u = !1,
    MenuListProps: m = {},
    onClose: f,
    open: F,
    PaperProps: j = {},
    PopoverClasses: _,
    transitionDuration: x = "auto",
    TransitionProps: {
      onEntering: d
    } = {},
    variant: P = "selectedMenu",
    slots: b = {},
    slotProps: N = {}
  } = s, S = E(s.TransitionProps, oo), w = E(s, eo), M = W(), n = i({}, s, {
    autoFocus: c,
    disableAutoFocusItem: u,
    MenuListProps: m,
    onEntering: d,
    PaperProps: j,
    transitionDuration: x,
    TransitionProps: S,
    variant: P
  }), v = so(n), A = c && !u && F, T = l.useRef(null), z = (e, p) => {
    T.current && T.current.adjustStyleForScrollbar(e, {
      direction: M ? "rtl" : "ltr"
    }), d && d(e, p);
  }, K = (e) => {
    e.key === "Tab" && (e.preventDefault(), f && f(e, "tabKeyDown"));
  };
  let a = -1;
  l.Children.map(g, (e, p) => {
    /* @__PURE__ */ l.isValidElement(e) && (process.env.NODE_ENV !== "production" && G(e), e.props.disabled || (P === "selectedMenu" && e.props.selected || a === -1) && (a = p));
  });
  const C = (O = b.paper) != null ? O : ao, U = (R = N.paper) != null ? R : j, V = L({
    elementType: b.root,
    externalSlotProps: N.root,
    ownerState: n,
    className: [v.root, D]
  }), k = L({
    elementType: C,
    externalSlotProps: U,
    ownerState: n,
    className: v.paper
  });
  return /* @__PURE__ */ I(no, i({
    onClose: f,
    anchorOrigin: {
      vertical: "bottom",
      horizontal: M ? "right" : "left"
    },
    transformOrigin: M ? to : ro,
    slots: {
      paper: C,
      root: b.root
    },
    slotProps: {
      root: V,
      paper: k
    },
    open: F,
    ref: y,
    transitionDuration: x,
    TransitionProps: i({
      onEntering: z
    }, S),
    ownerState: n
  }, w, {
    classes: _,
    children: /* @__PURE__ */ I(po, i({
      onKeyDown: K,
      actions: T,
      autoFocus: c && (a === -1 || u),
      autoFocusItem: A,
      variant: P
    }, m, {
      className: H(v.list, m.className),
      children: g
    }))
  }));
});
process.env.NODE_ENV !== "production" && (io.propTypes = {
  // ┌────────────────────────────── Warning ──────────────────────────────┐
  // │ These PropTypes are generated from the TypeScript type definitions. │
  // │    To update them, edit the d.ts file and run `pnpm proptypes`.     │
  // └─────────────────────────────────────────────────────────────────────┘
  /**
   * An HTML element, or a function that returns one.
   * It's used to set the position of the menu.
   */
  anchorEl: o.oneOfType([Z, o.func]),
  /**
   * If `true` (Default) will focus the `[role="menu"]` if no focusable child is found. Disabled
   * children are not focusable. If you set this prop to `false` focus will be placed
   * on the parent modal container. This has severe accessibility implications
   * and should only be considered if you manage focus otherwise.
   * @default true
   */
  autoFocus: o.bool,
  /**
   * Menu contents, normally `MenuItem`s.
   */
  children: o.node,
  /**
   * Override or extend the styles applied to the component.
   */
  classes: o.object,
  /**
   * @ignore
   */
  className: o.string,
  /**
   * When opening the menu will not focus the active item but the `[role="menu"]`
   * unless `autoFocus` is also set to `false`. Not using the default means not
   * following WAI-ARIA authoring practices. Please be considerate about possible
   * accessibility implications.
   * @default false
   */
  disableAutoFocusItem: o.bool,
  /**
   * Props applied to the [`MenuList`](/material-ui/api/menu-list/) element.
   * @default {}
   */
  MenuListProps: o.object,
  /**
   * Callback fired when the component requests to be closed.
   *
   * @param {object} event The event source of the callback.
   * @param {string} reason Can be: `"escapeKeyDown"`, `"backdropClick"`, `"tabKeyDown"`.
   */
  onClose: o.func,
  /**
   * If `true`, the component is shown.
   */
  open: o.bool.isRequired,
  /**
   * @ignore
   */
  PaperProps: o.object,
  /**
   * `classes` prop applied to the [`Popover`](/material-ui/api/popover/) element.
   */
  PopoverClasses: o.object,
  /**
   * The extra props for the slot components.
   * You can override the existing props or add new ones.
   *
   * @default {}
   */
  slotProps: o.shape({
    paper: o.oneOfType([o.func, o.object]),
    root: o.oneOfType([o.func, o.object])
  }),
  /**
   * The components used for each slot inside.
   *
   * @default {}
   */
  slots: o.shape({
    paper: o.elementType,
    root: o.elementType
  }),
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx: o.oneOfType([o.arrayOf(o.oneOfType([o.func, o.object, o.bool])), o.func, o.object]),
  /**
   * The length of the transition in `ms`, or 'auto'
   * @default 'auto'
   */
  transitionDuration: o.oneOfType([o.oneOf(["auto"]), o.number, o.shape({
    appear: o.number,
    enter: o.number,
    exit: o.number
  })]),
  /**
   * Props applied to the transition element.
   * By default, the element is based on this [`Transition`](https://reactcommunity.org/react-transition-group/transition/) component.
   * @default {}
   */
  TransitionProps: o.object,
  /**
   * The variant to use. Use `menu` to prevent selected items from impacting the initial focus.
   * @default 'selectedMenu'
   */
  variant: o.oneOf(["menu", "selectedMenu"])
});
export {
  ao as MenuPaper,
  io as default
};
