import * as c from "react";
import { composeEventHandlers as P } from "../../../../../@radix-ui_primitive@1.1.0/node_modules/@radix-ui/primitive/dist/index.js";
import { useComposedRefs as A } from "../../../../../@radix-ui_react-compose-refs@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-compose-refs/dist/index.js";
import { createContextScope as G } from "../../../../../@radix-ui_react-context@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-context/dist/index.js";
import { DismissableLayer as H } from "../../../../../@radix-ui_react-dismissable-layer@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@t_540819d22b5f34e77f512765c1a78ce5/node_modules/@radix-ui/react-dismissable-layer/dist/index.js";
import { useFocusGuards as K } from "../../../../../@radix-ui_react-focus-guards@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-focus-guards/dist/index.js";
import { FocusScope as $ } from "../../../../../@radix-ui_react-focus-scope@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_r_c5413b53d4356de1cc2ff1163dee68dc/node_modules/@radix-ui/react-focus-scope/dist/index.js";
import { useId as U } from "../../../../../@radix-ui_react-id@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-id/dist/index.js";
import { createPopperScope as O, Root as V, Anchor as _, Content as W, Arrow as Z } from "../../../../../@radix-ui_react-popper@1.2.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react@_0c236d22233b5684ecf8a3d8d1b24562/node_modules/@radix-ui/react-popper/dist/index.js";
import { Portal as q } from "../../../../../@radix-ui_react-portal@1.1.1_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react@_d91fd04d10d265136bf0d35a7b9375b2/node_modules/@radix-ui/react-portal/dist/index.js";
import { Presence as E } from "../../../../../@radix-ui_react-presence@1.1.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_reac_4a916339a724b4591202705df11dd5fc/node_modules/@radix-ui/react-presence/dist/index.js";
import { Primitive as w } from "../../../../../@radix-ui_react-primitive@2.0.0_@types_react-dom@18.3.6_@types_react@18.3.3__@types_rea_bdcf182289a3a76356f07e550726e479/node_modules/@radix-ui/react-primitive/dist/index.js";
import { Slot as z } from "../../../../../@radix-ui_react-slot@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-slot/dist/index.js";
import { useControllableState as B } from "../../../../../@radix-ui_react-use-controllable-state@1.1.0_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/@radix-ui/react-use-controllable-state/dist/index.js";
import { hideOthers as J } from "../../../../../aria-hidden@1.2.6/node_modules/aria-hidden/dist/es2015/index.js";
import Q from "../../../../../react-remove-scroll@2.5.7_@types_react@18.3.3_react@18.3.0-canary-3d9b20132-20240124/node_modules/react-remove-scroll/dist/es2015/Combination.js";
import { j as p } from "../../../../../../../_virtual/jsx-runtime.js";
var x = "Popover", [j, Ao] = G(x, [
  O
]), m = O(), [X, u] = j(x), b = (o) => {
  const {
    __scopePopover: n,
    children: t,
    open: s,
    defaultOpen: e,
    onOpenChange: r,
    modal: a = !1
  } = o, i = m(n), d = c.useRef(null), [v, g] = c.useState(!1), [h = !1, l] = B({
    prop: s,
    defaultProp: e,
    onChange: r
  });
  return /* @__PURE__ */ p.jsx(V, { ...i, children: /* @__PURE__ */ p.jsx(
    X,
    {
      scope: n,
      contentId: U(),
      triggerRef: d,
      open: h,
      onOpenChange: l,
      onOpenToggle: c.useCallback(() => l((C) => !C), [l]),
      hasCustomAnchor: v,
      onCustomAnchorAdd: c.useCallback(() => g(!0), []),
      onCustomAnchorRemove: c.useCallback(() => g(!1), []),
      modal: a,
      children: t
    }
  ) });
};
b.displayName = x;
var F = "PopoverAnchor", N = c.forwardRef(
  (o, n) => {
    const { __scopePopover: t, ...s } = o, e = u(F, t), r = m(t), { onCustomAnchorAdd: a, onCustomAnchorRemove: i } = e;
    return c.useEffect(() => (a(), () => i()), [a, i]), /* @__PURE__ */ p.jsx(_, { ...r, ...s, ref: n });
  }
);
N.displayName = F;
var y = "PopoverTrigger", S = c.forwardRef(
  (o, n) => {
    const { __scopePopover: t, ...s } = o, e = u(y, t), r = m(t), a = A(n, e.triggerRef), i = /* @__PURE__ */ p.jsx(
      w.button,
      {
        type: "button",
        "aria-haspopup": "dialog",
        "aria-expanded": e.open,
        "aria-controls": e.contentId,
        "data-state": L(e.open),
        ...s,
        ref: a,
        onClick: P(o.onClick, e.onOpenToggle)
      }
    );
    return e.hasCustomAnchor ? i : /* @__PURE__ */ p.jsx(_, { asChild: !0, ...r, children: i });
  }
);
S.displayName = y;
var R = "PopoverPortal", [Y, oo] = j(R, {
  forceMount: void 0
}), D = (o) => {
  const { __scopePopover: n, forceMount: t, children: s, container: e } = o, r = u(R, n);
  return /* @__PURE__ */ p.jsx(Y, { scope: n, forceMount: t, children: /* @__PURE__ */ p.jsx(E, { present: t || r.open, children: /* @__PURE__ */ p.jsx(q, { asChild: !0, container: e, children: s }) }) });
};
D.displayName = R;
var f = "PopoverContent", M = c.forwardRef(
  (o, n) => {
    const t = oo(f, o.__scopePopover), { forceMount: s = t.forceMount, ...e } = o, r = u(f, o.__scopePopover);
    return /* @__PURE__ */ p.jsx(E, { present: s || r.open, children: r.modal ? /* @__PURE__ */ p.jsx(eo, { ...e, ref: n }) : /* @__PURE__ */ p.jsx(ro, { ...e, ref: n }) });
  }
);
M.displayName = f;
var eo = c.forwardRef(
  (o, n) => {
    const t = u(f, o.__scopePopover), s = c.useRef(null), e = A(n, s), r = c.useRef(!1);
    return c.useEffect(() => {
      const a = s.current;
      if (a) return J(a);
    }, []), /* @__PURE__ */ p.jsx(Q, { as: z, allowPinchZoom: !0, children: /* @__PURE__ */ p.jsx(
      k,
      {
        ...o,
        ref: e,
        trapFocus: t.open,
        disableOutsidePointerEvents: !0,
        onCloseAutoFocus: P(o.onCloseAutoFocus, (a) => {
          a.preventDefault(), r.current || t.triggerRef.current?.focus();
        }),
        onPointerDownOutside: P(
          o.onPointerDownOutside,
          (a) => {
            const i = a.detail.originalEvent, d = i.button === 0 && i.ctrlKey === !0, v = i.button === 2 || d;
            r.current = v;
          },
          { checkForDefaultPrevented: !1 }
        ),
        onFocusOutside: P(
          o.onFocusOutside,
          (a) => a.preventDefault(),
          { checkForDefaultPrevented: !1 }
        )
      }
    ) });
  }
), ro = c.forwardRef(
  (o, n) => {
    const t = u(f, o.__scopePopover), s = c.useRef(!1), e = c.useRef(!1);
    return /* @__PURE__ */ p.jsx(
      k,
      {
        ...o,
        ref: n,
        trapFocus: !1,
        disableOutsidePointerEvents: !1,
        onCloseAutoFocus: (r) => {
          o.onCloseAutoFocus?.(r), r.defaultPrevented || (s.current || t.triggerRef.current?.focus(), r.preventDefault()), s.current = !1, e.current = !1;
        },
        onInteractOutside: (r) => {
          o.onInteractOutside?.(r), r.defaultPrevented || (s.current = !0, r.detail.originalEvent.type === "pointerdown" && (e.current = !0));
          const a = r.target;
          t.triggerRef.current?.contains(a) && r.preventDefault(), r.detail.originalEvent.type === "focusin" && e.current && r.preventDefault();
        }
      }
    );
  }
), k = c.forwardRef(
  (o, n) => {
    const {
      __scopePopover: t,
      trapFocus: s,
      onOpenAutoFocus: e,
      onCloseAutoFocus: r,
      disableOutsidePointerEvents: a,
      onEscapeKeyDown: i,
      onPointerDownOutside: d,
      onFocusOutside: v,
      onInteractOutside: g,
      ...h
    } = o, l = u(f, t), C = m(t);
    return K(), /* @__PURE__ */ p.jsx(
      $,
      {
        asChild: !0,
        loop: !0,
        trapped: s,
        onMountAutoFocus: e,
        onUnmountAutoFocus: r,
        children: /* @__PURE__ */ p.jsx(
          H,
          {
            asChild: !0,
            disableOutsidePointerEvents: a,
            onInteractOutside: g,
            onEscapeKeyDown: i,
            onPointerDownOutside: d,
            onFocusOutside: v,
            onDismiss: () => l.onOpenChange(!1),
            children: /* @__PURE__ */ p.jsx(
              W,
              {
                "data-state": L(l.open),
                role: "dialog",
                id: l.contentId,
                ...C,
                ...h,
                ref: n,
                style: {
                  ...h.style,
                  "--radix-popover-content-transform-origin": "var(--radix-popper-transform-origin)",
                  "--radix-popover-content-available-width": "var(--radix-popper-available-width)",
                  "--radix-popover-content-available-height": "var(--radix-popper-available-height)",
                  "--radix-popover-trigger-width": "var(--radix-popper-anchor-width)",
                  "--radix-popover-trigger-height": "var(--radix-popper-anchor-height)"
                }
              }
            )
          }
        )
      }
    );
  }
), I = "PopoverClose", T = c.forwardRef(
  (o, n) => {
    const { __scopePopover: t, ...s } = o, e = u(I, t);
    return /* @__PURE__ */ p.jsx(
      w.button,
      {
        type: "button",
        ...s,
        ref: n,
        onClick: P(o.onClick, () => e.onOpenChange(!1))
      }
    );
  }
);
T.displayName = I;
var to = "PopoverArrow", no = c.forwardRef(
  (o, n) => {
    const { __scopePopover: t, ...s } = o, e = m(t);
    return /* @__PURE__ */ p.jsx(Z, { ...e, ...s, ref: n });
  }
);
no.displayName = to;
function L(o) {
  return o ? "open" : "closed";
}
var Oo = b, _o = N, Eo = S, wo = D, jo = M, bo = T;
export {
  _o as Anchor,
  bo as Close,
  jo as Content,
  b as Popover,
  N as PopoverAnchor,
  no as PopoverArrow,
  T as PopoverClose,
  M as PopoverContent,
  D as PopoverPortal,
  S as PopoverTrigger,
  wo as Portal,
  Oo as Root,
  Eo as Trigger,
  Ao as createPopoverScope
};
//# sourceMappingURL=index.js.map
