/**
 * @license MIT
 * author: Cube Dev Team
 * @cube-dev/ui-kit v0.0.0-canary-5e810c3
 * Released under the MIT license.
 */

import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useMemo, } from 'react';
import { defaultNavigationAdapter } from './providers/navigationAdapter.default.js';
import { EventBusProvider } from './utils/react/useEventBus.js';
export const UIKitContext = createContext({
    navigation: defaultNavigationAdapter,
});
export function Provider(allProps) {
    let { children, insideForm, isDisabled, isReadOnly, isRequired, validationState, navigation, root, ref, } = allProps;
    const parentContext = useContext(UIKitContext);
    // Wrap with EventBusProvider for menu synchronization
    children = _jsx(EventBusProvider, { children: 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 (_jsx(UIKitContext.Provider, { value: newValue, children: children }));
}
export function useProviderProps(props) {
    const contextProps = useContext(UIKitContext);
    return { ...contextProps, ...props };
}

        