import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2019-2026 GoodData Corporation
import { createContext, useContext } from "react";
import { ErrorComponent, LoadingComponent, UnexpectedSdkError, } from "@gooddata/sdk-ui";
const ThrowMissingComponentError = (componentName) => () => {
    throw new UnexpectedSdkError(`Component: ${componentName} is missing in the DashboardComponentsProvider.`);
};
/**
 * @internal
 */
const DashboardComponentsContext = createContext({
    ErrorComponent: ErrorComponent,
    LoadingComponent: LoadingComponent,
    LayoutComponent: ThrowMissingComponentError("LayoutComponent"),
    InsightComponentProvider: ThrowMissingComponentError("InsightComponent"),
    InsightBodyComponentProvider: ThrowMissingComponentError("InsightBodyComponent"),
    InsightMenuButtonComponentProvider: ThrowMissingComponentError("InsightMenuButtonComponent"),
    InsightMenuComponentProvider: ThrowMissingComponentError("InsightMenuComponent"),
    InsightMenuTitleComponentProvider: ThrowMissingComponentError("InsightMenuTitleComponent"),
    RichTextMenuComponentProvider: ThrowMissingComponentError("RichTextMenuComponent"),
    RichTextMenuTitleComponentProvider: ThrowMissingComponentError("RichTextMenuTitleComponentProvider"),
    RichTextComponentProvider: ThrowMissingComponentError("RichTextComponent"),
    VisualizationSwitcherComponentProvider: ThrowMissingComponentError("VisualizationSwitcherComponent"),
    WidgetComponentProvider: ThrowMissingComponentError("WidgetComponent"),
    ButtonBarComponent: ThrowMissingComponentError("ButtonBarComponent"),
    MenuButtonComponent: ThrowMissingComponentError("MenuButtonComponent"),
    TitleComponent: ThrowMissingComponentError("TitleComponent"),
    TopBarComponent: ThrowMissingComponentError("TopBarComponent"),
    ToolbarComponent: ThrowMissingComponentError("ToolbarComponent"),
    ScheduledEmailDialogComponent: ThrowMissingComponentError("ScheduledEmailDialogComponent"),
    ScheduledEmailManagementDialogComponent: ThrowMissingComponentError("ScheduledEmailManagementDialogComponent"),
    AlertingManagementDialogComponent: ThrowMissingComponentError("AlertingManagementDialogComponent"),
    AlertingDialogComponent: ThrowMissingComponentError("AlertingDialogComponent"),
    ShareDialogComponent: ThrowMissingComponentError("ShareDialogComponent"),
    SaveAsDialogComponent: ThrowMissingComponentError("SaveAsDialogComponent"),
    DashboardAttributeFilterComponentProvider: ThrowMissingComponentError("DashboardAttributeFilterComponentProvider"),
    DashboardDateFilterComponentProvider: ThrowMissingComponentError("DashboardDateFilterComponentProvider"),
    DashboardMeasureValueFilterComponentProvider: ThrowMissingComponentError("DashboardMeasureValueFilterComponentProvider"),
    DashboardFilterGroupComponentProvider: ThrowMissingComponentError("DashboardFilterGroupComponentProvider"),
    FilterBarComponent: ThrowMissingComponentError("FilterBarComponent"),
    SidebarComponent: ThrowMissingComponentError("SidebarComponent"),
    InsightWidgetComponentSet: null, // TODO how to throw here
    RichTextWidgetComponentSet: null, // TODO how to throw here
    VisualizationSwitcherWidgetComponentSet: null, // TODO how to throw here
    DashboardLayoutWidgetComponentSet: null, // TODO how to throw here
    AttributeFilterComponentSet: null, // TODO how to throw here
    DateFilterComponentSet: null, // TODO how to throw here
    EmptyLayoutDropZoneBodyComponent: ThrowMissingComponentError("EmptyLayoutDropZoneBodyComponent"),
    SaveButtonComponent: ThrowMissingComponentError("SaveButtonComponent"),
    DashboardContentComponentProvider: ThrowMissingComponentError("DashboardContentComponentProvider"),
    VisualizationSwitcherToolbarComponentProvider: ThrowMissingComponentError("VisualizationSwitcherToolbarComponentProvider"),
    SettingButtonComponent: ThrowMissingComponentError("SettingButtonComponent"),
    DashboardSettingsDialogComponent: ThrowMissingComponentError("DashboardSettingsDialogComponent"),
    ShowAsTableButtonComponentProvider: ThrowMissingComponentError("ShowAsTableButtonComponentProvider"),
    DrillDialogExportDropdownComponentProvider: ThrowMissingComponentError("DrillDialogExportDropdownComponentProvider"),
});
DashboardComponentsContext.displayName = "DashboardComponentsContext";
/**
 * @internal
 */
export const useDashboardComponentsContext = (localComponentOverrides) => {
    const globalComponents = useContext(DashboardComponentsContext);
    // cannot just spread here, we only want to use overrides that are not undefined
    return Object.keys(globalComponents).reduce((acc, key) => {
        acc[key] = localComponentOverrides?.[key] ?? globalComponents[key];
        return acc;
    }, {});
};
/**
 * @internal
 */
export function DashboardComponentsProvider({ children, ...components }) {
    return (_jsx(DashboardComponentsContext.Provider, { value: components, children: children }));
}
