"use client";
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
import { createContext, useContext } from "react";
import { jsx } from "react/jsx-runtime";

//#region src/components/client/Popover/UDSPopoverConfigProvider.tsx
const PopoverContext = createContext(void 0);
const UDSPopoverConfigProvider = ({ children, value }) => {
	const existingContext = useContext(PopoverContext);
	if ("type" in value) {
		if (!existingContext) throw new Error("Cannot merge context values without an existing PopoverContext");
		return /* @__PURE__ */ jsx(PopoverContext.Provider, {
			value: {
				...existingContext,
				...value.value
			},
			children
		});
	}
	return /* @__PURE__ */ jsx(PopoverContext.Provider, {
		value,
		children
	});
};
UDSPopoverConfigProvider.displayName = "UDSPopoverConfigProvider";
function usePopoverConfig(options) {
	const context = useContext(PopoverContext);
	if (!context) throw new Error("usePopoverConfig must be used within a UDSConfigProvider or UDSPopoverConfigProvider");
	const { placementMap, placement, ...contextRest } = context;
	return {
		...contextRest,
		ariaKitPlacement: placementMap[options?.placement ?? placement]
	};
}

//#endregion
export { UDSPopoverConfigProvider, usePopoverConfig };