import no from "./index-objectWithoutPropertiesLoose.js";
import n from "./index-extends.js";
import * as $ from "react";
import o from "./index-_virtual16.js";
import { clsx as z } from "./index-clsx.js";
import q from "./index-styled.js";
import ro from "./index-useModal.js";
import { getModalUtilityClass as lo } from "./index-modalClasses.js";
import { jsx as T, jsxs as co } from "react/jsx-runtime";
import { useDefaultProps as ao } from "./index-DefaultPropsProvider.js";
import K from "./index-useSlotProps.js";
import po from "./index-Portal.js";
import io from "./index-FocusTrap.js";
import uo from "./index-Backdrop.js";
import fo from "./index-composeClasses.js";
import mo from "./index-elementAcceptingRef.js";
import bo from "./index-HTMLElementType.js";
const ko = ["BackdropComponent", "BackdropProps", "classes", "className", "closeAfterTransition", "children", "container", "component", "components", "componentsProps", "disableAutoFocus", "disableEnforceFocus", "disableEscapeKeyDown", "disablePortal", "disableRestoreFocus", "disableScrollLock", "hideBackdrop", "keepMounted", "onBackdropClick", "onClose", "onTransitionEnter", "onTransitionExited", "open", "slotProps", "slots", "theme"], Po = (s) => {
  const {
    open: e,
    exited: t,
    classes: a
  } = s;
  return fo({
    root: ["root", !e && t && "hidden"],
    backdrop: ["backdrop"]
  }, lo, a);
}, To = q("div", {
  name: "MuiModal",
  slot: "Root",
  overridesResolver: (s, e) => {
    const {
      ownerState: t
    } = s;
    return [e.root, !t.open && t.exited && e.hidden];
  }
})(({
  theme: s,
  ownerState: e
}) => n({
  position: "fixed",
  zIndex: (s.vars || s).zIndex.modal,
  right: 0,
  bottom: 0,
  top: 0,
  left: 0
}, !e.open && e.exited && {
  visibility: "hidden"
})), xo = q(uo, {
  name: "MuiModal",
  slot: "Backdrop",
  overridesResolver: (s, e) => e.backdrop
})({
  zIndex: -1
}), yo = /* @__PURE__ */ $.forwardRef(function(e, t) {
  var a, f, x, y, h, v;
  const m = ao({
    name: "MuiModal",
    props: e
  }), {
    BackdropComponent: E = xo,
    BackdropProps: b,
    className: U,
    closeAfterTransition: W = !1,
    children: B,
    container: V,
    component: G,
    components: R = {},
    componentsProps: M = {},
    disableAutoFocus: C = !1,
    disableEnforceFocus: F = !1,
    disableEscapeKeyDown: J = !1,
    disablePortal: S = !1,
    disableRestoreFocus: j = !1,
    disableScrollLock: Q = !1,
    hideBackdrop: N = !1,
    keepMounted: _ = !1,
    onBackdropClick: g,
    open: O,
    slotProps: p,
    slots: i
    // eslint-disable-next-line react/prop-types
  } = m, X = no(m, ko), A = n({}, m, {
    closeAfterTransition: W,
    disableAutoFocus: C,
    disableEnforceFocus: F,
    disableEscapeKeyDown: J,
    disablePortal: S,
    disableRestoreFocus: j,
    disableScrollLock: Q,
    hideBackdrop: N,
    keepMounted: _
  }), {
    getRootProps: Y,
    getBackdropProps: Z,
    getTransitionProps: H,
    portalRef: oo,
    isTopModal: eo,
    exited: w,
    hasTransition: D
  } = ro(n({}, A, {
    rootRef: t
  })), c = n({}, A, {
    exited: w
  }), r = Po(c), d = {};
  if (B.props.tabIndex === void 0 && (d.tabIndex = "-1"), D) {
    const {
      onEnter: l,
      onExited: u
    } = H();
    d.onEnter = l, d.onExited = u;
  }
  const I = (a = (f = i == null ? void 0 : i.root) != null ? f : R.Root) != null ? a : To, L = (x = (y = i == null ? void 0 : i.backdrop) != null ? y : R.Backdrop) != null ? x : E, k = (h = p == null ? void 0 : p.root) != null ? h : M.root, P = (v = p == null ? void 0 : p.backdrop) != null ? v : M.backdrop, so = K({
    elementType: I,
    externalSlotProps: k,
    externalForwardedProps: X,
    getSlotProps: Y,
    additionalProps: {
      ref: t,
      as: G
    },
    ownerState: c,
    className: z(U, k == null ? void 0 : k.className, r == null ? void 0 : r.root, !c.open && c.exited && (r == null ? void 0 : r.hidden))
  }), to = K({
    elementType: L,
    externalSlotProps: P,
    additionalProps: b,
    getSlotProps: (l) => Z(n({}, l, {
      onClick: (u) => {
        g && g(u), l != null && l.onClick && l.onClick(u);
      }
    })),
    className: z(P == null ? void 0 : P.className, b == null ? void 0 : b.className, r == null ? void 0 : r.backdrop),
    ownerState: c
  });
  return !_ && !O && (!D || w) ? null : /* @__PURE__ */ T(po, {
    ref: oo,
    container: V,
    disablePortal: S,
    children: /* @__PURE__ */ co(I, n({}, so, {
      children: [!N && E ? /* @__PURE__ */ T(L, n({}, to)) : null, /* @__PURE__ */ T(io, {
        disableEnforceFocus: F,
        disableAutoFocus: C,
        disableRestoreFocus: j,
        isEnabled: eo,
        open: O,
        children: /* @__PURE__ */ $.cloneElement(B, d)
      })]
    }))
  });
});
process.env.NODE_ENV !== "production" && (yo.propTypes = {
  // ┌────────────────────────────── Warning ──────────────────────────────┐
  // │ These PropTypes are generated from the TypeScript type definitions. │
  // │    To update them, edit the d.ts file and run `pnpm proptypes`.     │
  // └─────────────────────────────────────────────────────────────────────┘
  /**
   * A backdrop component. This prop enables custom backdrop rendering.
   * @deprecated Use `slots.backdrop` instead. While this prop currently works, it will be removed in the next major version.
   * Use the `slots.backdrop` prop to make your application ready for the next version of Material UI.
   * @default styled(Backdrop, {
   *   name: 'MuiModal',
   *   slot: 'Backdrop',
   *   overridesResolver: (props, styles) => {
   *     return styles.backdrop;
   *   },
   * })({
   *   zIndex: -1,
   * })
   */
  BackdropComponent: o.elementType,
  /**
   * Props applied to the [`Backdrop`](/material-ui/api/backdrop/) element.
   * @deprecated Use `slotProps.backdrop` instead.
   */
  BackdropProps: o.object,
  /**
   * A single child content element.
   */
  children: mo.isRequired,
  /**
   * Override or extend the styles applied to the component.
   */
  classes: o.object,
  /**
   * @ignore
   */
  className: o.string,
  /**
   * When set to true the Modal waits until a nested Transition is completed before closing.
   * @default false
   */
  closeAfterTransition: o.bool,
  /**
   * The component used for the root node.
   * Either a string to use a HTML element or a component.
   */
  component: o.elementType,
  /**
   * The components used for each slot inside.
   *
   * This prop is an alias for the `slots` prop.
   * It's recommended to use the `slots` prop instead.
   *
   * @default {}
   */
  components: o.shape({
    Backdrop: o.elementType,
    Root: o.elementType
  }),
  /**
   * The extra props for the slot components.
   * You can override the existing props or add new ones.
   *
   * This prop is an alias for the `slotProps` prop.
   * It's recommended to use the `slotProps` prop instead, as `componentsProps` will be deprecated in the future.
   *
   * @default {}
   */
  componentsProps: o.shape({
    backdrop: o.oneOfType([o.func, o.object]),
    root: o.oneOfType([o.func, o.object])
  }),
  /**
   * An HTML element or function that returns one.
   * The `container` will have the portal children appended to it.
   *
   * You can also provide a callback, which is called in a React layout effect.
   * This lets you set the container from a ref, and also makes server-side rendering possible.
   *
   * By default, it uses the body of the top-level document object,
   * so it's simply `document.body` most of the time.
   */
  container: o.oneOfType([bo, o.func]),
  /**
   * If `true`, the modal will not automatically shift focus to itself when it opens, and
   * replace it to the last focused element when it closes.
   * This also works correctly with any modal children that have the `disableAutoFocus` prop.
   *
   * Generally this should never be set to `true` as it makes the modal less
   * accessible to assistive technologies, like screen readers.
   * @default false
   */
  disableAutoFocus: o.bool,
  /**
   * If `true`, the modal will not prevent focus from leaving the modal while open.
   *
   * Generally this should never be set to `true` as it makes the modal less
   * accessible to assistive technologies, like screen readers.
   * @default false
   */
  disableEnforceFocus: o.bool,
  /**
   * If `true`, hitting escape will not fire the `onClose` callback.
   * @default false
   */
  disableEscapeKeyDown: o.bool,
  /**
   * The `children` will be under the DOM hierarchy of the parent component.
   * @default false
   */
  disablePortal: o.bool,
  /**
   * If `true`, the modal will not restore focus to previously focused element once
   * modal is hidden or unmounted.
   * @default false
   */
  disableRestoreFocus: o.bool,
  /**
   * Disable the scroll lock behavior.
   * @default false
   */
  disableScrollLock: o.bool,
  /**
   * If `true`, the backdrop is not rendered.
   * @default false
   */
  hideBackdrop: o.bool,
  /**
   * Always keep the children in the DOM.
   * This prop can be useful in SEO situation or
   * when you want to maximize the responsiveness of the Modal.
   * @default false
   */
  keepMounted: o.bool,
  /**
   * Callback fired when the backdrop is clicked.
   * @deprecated Use the `onClose` prop with the `reason` argument to handle the `backdropClick` events.
   */
  onBackdropClick: o.func,
  /**
   * Callback fired when the component requests to be closed.
   * The `reason` parameter can optionally be used to control the response to `onClose`.
   *
   * @param {object} event The event source of the callback.
   * @param {string} reason Can be: `"escapeKeyDown"`, `"backdropClick"`.
   */
  onClose: o.func,
  /**
   * A function called when a transition enters.
   */
  onTransitionEnter: o.func,
  /**
   * A function called when a transition has exited.
   */
  onTransitionExited: o.func,
  /**
   * If `true`, the component is shown.
   */
  open: o.bool.isRequired,
  /**
   * The props used for each slot inside the Modal.
   * @default {}
   */
  slotProps: o.shape({
    backdrop: o.oneOfType([o.func, o.object]),
    root: o.oneOfType([o.func, o.object])
  }),
  /**
   * The components used for each slot inside the Modal.
   * Either a string to use a HTML element or a component.
   * @default {}
   */
  slots: o.shape({
    backdrop: 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])
});
export {
  yo as default
};
