"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);

// packages/components/src/menu/popover.tsx
var popover_exports = {};
__export(popover_exports, {
  Popover: () => Popover
});
module.exports = __toCommonJS(popover_exports);
var Ariakit = __toESM(require("@ariakit/react"), 1);
var import_element = require("@wordpress/element");
var Styled = __toESM(require("./styles.cjs"), 1);
var import_context = require("./context.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var Popover = (0, import_element.forwardRef)(function Popover2({
  gutter,
  children,
  shift,
  modal = true,
  ...otherProps
}, ref) {
  const menuContext = (0, import_element.useContext)(import_context.Context);
  const appliedPlacementSide = Ariakit.useStoreState(menuContext?.store, "currentPlacement")?.split("-")[0];
  const hideOnEscape = (0, import_element.useCallback)((event) => {
    event.preventDefault();
    return true;
  }, []);
  const computedDirection = Ariakit.useStoreState(menuContext?.store, "rtl") ? "rtl" : "ltr";
  const wrapperProps = (0, import_element.useMemo)(() => ({
    dir: computedDirection,
    style: {
      direction: computedDirection
    }
  }), [computedDirection]);
  if (!menuContext?.store) {
    throw new Error("Menu.Popover can only be rendered inside a Menu component");
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Ariakit.Menu, {
    ...otherProps,
    ref,
    modal,
    store: menuContext.store,
    gutter: gutter !== null && gutter !== void 0 ? gutter : menuContext.store.parent ? 0 : 8,
    shift: shift !== null && shift !== void 0 ? shift : menuContext.store.parent ? -4 : 0,
    hideOnHoverOutside: false,
    "data-side": appliedPlacementSide,
    wrapperProps,
    hideOnEscape,
    unmountOnHide: true,
    render: (renderProps) => (
      // Two wrappers are needed for the entry animation, where the menu
      // container scales with a different factor than its contents.
      // The {...renderProps} are passed to the inner wrapper, so that the
      // menu element is the direct parent of the menu item elements.
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Styled.PopoverOuterWrapper, {
        variant: menuContext.variant,
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Styled.PopoverInnerWrapper, {
          ...renderProps
        })
      })
    ),
    children
  });
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Popover
});
//# sourceMappingURL=popover.cjs.map
