import React, { useState } from 'react';
import { showToastCompat } from '@wix/bex-core';
import { usePageLocation } from '@wix/bex-core/react';
import { useEssentials } from '@wix/yoshi-flow-bm/fe-essentials-giza';
import { useComponentLoaded, usePlatformApi } from '@wix/yoshi-flow-bm';
import { CairoProvider } from '../providers';
import { buildWixPatternsEssentials } from './buildWixPatternsEssentials';
import { minimalRequiredRuntimeCheck } from '../utils/minimalRequiredRuntimeCheck';
export function WixPatternsGizaProvider(props) {
    if (process.env.NODE_ENV !== 'production') {
        minimalRequiredRuntimeCheck({
            packageJson: require('@wix/yoshi-flow-bm/package.json'),
            required: '^6.103.0',
        });
    }
    const { children, value: wixPatternsEssentialsOverridesProp, contextType = 'ACCOUNT', } = props;
    const { showToast, navigateTo, onBeforeUnload, getHostContainer } = usePlatformApi();
    const essentials = useEssentials();
    const [wixPatternsEssentialsOverrides] = useState(() => ({
        usePageLocation,
        navigateTo: ({ pageId, appState, referrer, relativeUrl }) => {
            navigateTo({
                pageId,
                appState: appState || relativeUrl,
                referrer,
            });
        },
        getHostContainer,
        showToast: showToastCompat(showToast),
        useAppLoaded: () => {
            useComponentLoaded();
        },
        onBeforeUnload,
        ...wixPatternsEssentialsOverridesProp,
    }));
    const [wixPatternsEssentials] = useState(() => buildWixPatternsEssentials(essentials, {
        overrides: wixPatternsEssentialsOverrides,
    }));
    return (React.createElement(CairoProvider, { ...props, value: wixPatternsEssentials, contextType: contextType }, children));
}
//# sourceMappingURL=WixPatternsGizaProvider.js.map