"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const rem = require("../../../core/utils/units-converters/rem.cjs");
require("react");
const closeOnEscape = require("../../../core/utils/close-on-escape/close-on-escape.cjs");
require("clsx");
const useProps = require("../../../core/MantineProvider/use-props/use-props.cjs");
const Box = require("../../../core/Box/Box.cjs");
const factory = require("../../../core/factory/factory.cjs");
const FloatingArrow = require("../../Floating/FloatingArrow/FloatingArrow.cjs");
const FocusTrap = require("../../FocusTrap/FocusTrap.cjs");
const OptionalPortal = require("../../Portal/OptionalPortal.cjs");
const Transition = require("../../Transition/Transition.cjs");
const Popover_context = require("../Popover.context.cjs");
const Popover_module_css = require("../Popover.module.css.cjs");
const useFocusReturn = require("../../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-focus-return/use-focus-return.cjs");
const useMergedRef = require("../../../../../../../../@mantine_hooks@7.15.2_react@18.3.1/node_modules/@mantine/hooks/esm/use-merged-ref/use-merged-ref.cjs");
const defaultProps = {};
const PopoverDropdown = factory.factory((_props, ref) => {
  var _a, _b, _c, _d;
  const props = useProps.useProps("PopoverDropdown", defaultProps, _props);
  const {
    className,
    style,
    vars,
    children,
    onKeyDownCapture,
    variant,
    classNames,
    styles,
    ...others
  } = props;
  const ctx = Popover_context.usePopoverContext();
  const returnFocus = useFocusReturn.useFocusReturn({
    opened: ctx.opened,
    shouldReturnFocus: ctx.returnFocus
  });
  const accessibleProps = ctx.withRoles ? {
    "aria-labelledby": ctx.getTargetId(),
    id: ctx.getDropdownId(),
    role: "dialog",
    tabIndex: -1
  } : {};
  const mergedRef = useMergedRef.useMergedRef(ref, ctx.floating);
  if (ctx.disabled) {
    return null;
  }
  return /* @__PURE__ */ jsxRuntime.jsx(OptionalPortal.OptionalPortal, { ...ctx.portalProps, withinPortal: ctx.withinPortal, children: /* @__PURE__ */ jsxRuntime.jsx(
    Transition.Transition,
    {
      mounted: ctx.opened,
      ...ctx.transitionProps,
      transition: ((_a = ctx.transitionProps) == null ? void 0 : _a.transition) || "fade",
      duration: ((_b = ctx.transitionProps) == null ? void 0 : _b.duration) ?? 150,
      keepMounted: ctx.keepMounted,
      exitDuration: typeof ((_c = ctx.transitionProps) == null ? void 0 : _c.exitDuration) === "number" ? ctx.transitionProps.exitDuration : (_d = ctx.transitionProps) == null ? void 0 : _d.duration,
      children: (transitionStyles) => /* @__PURE__ */ jsxRuntime.jsx(FocusTrap.FocusTrap, { active: ctx.trapFocus && ctx.opened, innerRef: mergedRef, children: /* @__PURE__ */ jsxRuntime.jsxs(
        Box.Box,
        {
          ...accessibleProps,
          ...others,
          variant,
          onKeyDownCapture: closeOnEscape.closeOnEscape(ctx.onClose, {
            active: ctx.closeOnEscape,
            onTrigger: returnFocus,
            onKeyDown: onKeyDownCapture
          }),
          "data-position": ctx.placement,
          "data-fixed": ctx.floatingStrategy === "fixed" || void 0,
          ...ctx.getStyles("dropdown", {
            className,
            props,
            classNames,
            styles,
            style: [
              {
                ...transitionStyles,
                zIndex: ctx.zIndex,
                top: ctx.y ?? 0,
                left: ctx.x ?? 0,
                width: ctx.width === "target" ? void 0 : rem.rem(ctx.width)
              },
              ctx.resolvedStyles.dropdown,
              styles == null ? void 0 : styles.dropdown,
              style
            ]
          }),
          children: [
            children,
            /* @__PURE__ */ jsxRuntime.jsx(
              FloatingArrow.FloatingArrow,
              {
                ref: ctx.arrowRef,
                arrowX: ctx.arrowX,
                arrowY: ctx.arrowY,
                visible: ctx.withArrow,
                position: ctx.placement,
                arrowSize: ctx.arrowSize,
                arrowRadius: ctx.arrowRadius,
                arrowOffset: ctx.arrowOffset,
                arrowPosition: ctx.arrowPosition,
                ...ctx.getStyles("arrow", {
                  props,
                  classNames,
                  styles
                })
              }
            )
          ]
        }
      ) })
    }
  ) });
});
PopoverDropdown.classes = Popover_module_css.default;
PopoverDropdown.displayName = "@mantine/core/PopoverDropdown";
exports.PopoverDropdown = PopoverDropdown;
