"use client";
import { c as e, t } from "./createBaseUIEventDetails-ChcQXp54.js";
import { n } from "./shadowDom-C-4Ejp9R.js";
import { G as r, K as i, U as a, q as o } from "./popupStateMapping-PdIQcWEz.js";
import * as s from "react";
import * as c from "react-dom";
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/utils/popups/useTriggerFocusGuards.js
function l(l, u) {
	let d = s.useRef(null);
	function f(n) {
		c.flushSync(() => {
			l.setOpen(!1, t(e, n.nativeEvent, n.currentTarget));
		}), i(d.current)?.focus();
	}
	function p(i) {
		let s = l.select("positionerElement");
		if (s && o(i, s)) l.context.beforeContentFocusGuardRef.current?.focus();
		else {
			c.flushSync(() => {
				l.setOpen(!1, t(e, i.nativeEvent, i.currentTarget));
			});
			let o = r(l.context.triggerFocusTargetRef.current || u.current);
			for (; o !== null && n(s, o);) {
				let e = o;
				if (o = a(o), o === e) break;
			}
			o?.focus();
		}
	}
	return {
		preFocusGuardRef: d,
		handlePreFocusGuardFocus: f,
		handleFocusTargetFocus: p
	};
}
//#endregion
export { l as t };
