/** @license MIT | @cube-dev/ui-kit v0.127.1 | Cube Dev Team */
import { EventBusProvider } from "./utils/react/useEventBus.js";
import { defaultNavigationAdapter } from "./providers/navigationAdapter.default.js";
import { createContext, useContext, useMemo } from "react";
import { jsx } from "react/jsx-runtime";

//#region src/provider.tsx
const UIKitContext = createContext({ navigation: defaultNavigationAdapter });
function Provider(allProps) {
	let { children, insideForm, isDisabled, isReadOnly, isRequired, validationState, navigation, root, ref } = allProps;
	const parentContext = useContext(UIKitContext);
	children = /* @__PURE__ */ jsx(EventBusProvider, { children });
	const props = useMemo(() => ({
		ref,
		insideForm,
		isDisabled,
		isReadOnly,
		isRequired,
		validationState,
		navigation: navigation || defaultNavigationAdapter,
		root
	}), [
		ref,
		insideForm,
		isDisabled,
		isReadOnly,
		isRequired,
		validationState,
		navigation,
		root
	]);
	const newValue = useMemo(() => {
		let newValue = Object.assign({}, parentContext);
		Object.keys(props).forEach((key) => {
			if (props[key] != null) newValue[key] = props[key];
		});
		return newValue;
	}, [parentContext, props]);
	return /* @__PURE__ */ jsx(UIKitContext.Provider, {
		value: newValue,
		children
	});
}
function useProviderProps(props) {
	return {
		...useContext(UIKitContext),
		...props
	};
}

//#endregion
export { Provider, UIKitContext, useProviderProps };
//# sourceMappingURL=provider.js.map