import React, { useState } from 'react';
import { Trans, useEssentials, useExperiments, useTranslation, } from '@wix/fe-essentials/react';
import { AppSettingsStorageStrategy, DataCapsule, } from '@wix/fe-essentials/data-capsule';
import { CairoProvider } from '../providers';
import ExtensionWidget from './ExtensionWidget';
import { Edit } from '@wix/wix-ui-icons-common';
import { ErrorHandler } from '@wix/fe-essentials/error-handler';
export function WixPatternsEssentialsTestProvider(props) {
    const { children, overrides, defaultExperiments, ...rest } = props;
    const { errorMonitor, httpClient, environment, createChildEssentials, experiments, biLoggerFactory, } = useEssentials();
    const [value] = useState(() => ({
        createEssentials: (options) => createChildEssentials({
            ...options,
            experiments: options.experiments &&
                'scopes' in options.experiments &&
                options.experiments?.scopes[0] === 'cairo'
                ? {
                    bag: {
                        ...(new URLSearchParams(window.location.search)
                            .get('id')
                            ?.includes('responsivetoolbar') && {
                            'specs.cairo.EnableResponsiveToolbar11420': 'true',
                        }),
                        ...(new URLSearchParams(window.location.search)
                            .get('id')
                            ?.includes('responsive-header') && {
                            'specs.cairo.CollectionPageMinWidth': 'true',
                        }),
                        ...defaultExperiments,
                        ...Object.fromEntries(new URLSearchParams(window.location.search)
                            .get('experiments')
                            ?.split(',')
                            ?.map((e) => {
                            const [spec = '', enabled = 'true'] = e.split(':');
                            return [spec, enabled];
                        }) ?? []),
                    },
                }
                : options.experiments,
        }),
        createComponentSettings: () => () => new DataCapsule({
            namespace: '',
            scope: 'cairo-test',
            strategy: new AppSettingsStorageStrategy({
                host: 'other',
                httpClient,
            }),
        }),
        errorMonitor,
        errorHandler: new ErrorHandler({
            biLoggerOrFactory: biLoggerFactory,
            createErrorMonitor: (options) => createChildEssentials({ errorMonitor: options }).errorMonitor,
            environment,
            createI18n: (options) => createChildEssentials({ i18n: options }).i18n,
        }).v2,
        useTranslation,
        Trans,
        useExperiments: () => useExperiments({ readOnly: true }),
        httpClient,
        experiments,
        ...overrides,
        user: {
            permissions: [],
            ...overrides?.user,
        },
        environment: {
            ...environment,
            componentId: [environment.artifactId, 'cairo-test-component'].join('.'),
            language: 'en-US',
            ...overrides?.environment,
        },
        environmentBI: {
            artifactId: environment.artifactId,
        },
        getHostContainer: (_) => ({
            getExtensions: () => Promise.resolve([
                {
                    title: 'Extension',
                    componentId: '',
                    Extension: (props) => React.createElement(ExtensionWidget, { ...props }),
                    menuItem: {
                        IconComponent: Edit,
                        structuredAction: () => alert('action'),
                    },
                },
            ]),
        }),
    }));
    return (React.createElement(CairoProvider, { localCache: true, value: value, ...rest }, children));
}
//# sourceMappingURL=WixPatternsEssentialsTestProvider.js.map