import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { DndProvider } from "@evil-internetmann/react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { BackendProvider, ErrorComponent as DefaultError, LoadingComponent as DefaultLoading, WorkspaceProvider, } from "@gooddata/sdk-ui";
import { OverlayController, OverlayControllerProvider } from "@gooddata/sdk-ui-kit";
import { ThemeProvider } from "@gooddata/sdk-ui-theme-provider";
import { DashboardStoreProvider } from "../../../model/react/DashboardStoreProvider.js";
import { DefaultAlertingDialogNew } from "../../alerting/DefaultAlertingDialog/DefaultAlertingDialogNew.js";
import { DefaultAlertingManagementDialogNew } from "../../alerting/DefaultAlertingManagementDialog/DefaultAlertingManagementDialogNew.js";
import { DASHBOARD_OVERLAYS_Z_INDEX } from "../../constants/zIndex.js";
import { DashboardComponentsProvider } from "../../dashboardContexts/DashboardComponentsContext.js";
import { DashboardConfigProvider } from "../../dashboardContexts/DashboardConfigContext.js";
import { DashboardCustomizationsProvider } from "../../dashboardContexts/DashboardCustomizationsContext.js";
import { ExportCsvDialogContextProvider } from "../../dashboardContexts/ExportCsvDialogContext.js";
import { ExportTabularPdfDialogContextProvider } from "../../dashboardContexts/ExportTabularPdfDialogContext.js";
import { ExportTemplateDialogContextProvider } from "../../dashboardContexts/ExportTemplateDialogContext.js";
import { ExportXlsxDialogContextProvider } from "../../dashboardContexts/ExportXlsxDialogContext.js";
import { DefaultDashboardSettingsDialog } from "../../dashboardSettingsDialog/DefaultDashboardSettingsDialog.js";
import { DefaultEmptyLayoutDropZoneBody } from "../../dragAndDrop/draggableWidget/DefaultEmptyLayoutDropZoneBody.js";
import { HoveredWidgetProvider } from "../../dragAndDrop/HoveredWidgetContext.js";
import { LayoutResizeStateProvider } from "../../dragAndDrop/LayoutResizeContext.js";
import { RenderModeAwareFilterBar } from "../../filterBar/filterBar/RenderModeAwareFilterBar.js";
import { DefaultDashboardLayout } from "../../flexibleLayout/DefaultDashboardLayout.js";
import { DefaultSaveAsDialog } from "../../saveAs/DefaultSaveAsDialog/index.js";
import { DefaultScheduledEmailDialog } from "../../scheduledEmail/DefaultScheduledEmailDialog/DefaultScheduledEmailDialog.js";
import { ScheduledEmailManagementDialog as DefaultScheduledEmailManagementDialog } from "../../scheduledEmail/DefaultScheduledEmailManagementDialog/DefaultScheduledEmailManagementDialog.js";
import { DefaultShareDialog } from "../../shareDialog/DefaultShareDialog.js";
import { HiddenToolbar } from "../../toolbar/HiddenToolbar.js";
import { DefaultSaveButton } from "../../topBar/buttonBar/button/saveButton/DefaultSaveButton.js";
import { DefaultSettingButton } from "../../topBar/buttonBar/button/settingButton/DefaultSettingButton.js";
import { DefaultButtonBar } from "../../topBar/buttonBar/DefaultButtonBar.js";
import { DefaultMenuButton } from "../../topBar/menuButton/DefaultMenuButton.js";
import { RenderModeAwareTitle } from "../../topBar/title/RenderModeAwareTitle.js";
import { RenderModeAwareTopBar } from "../../topBar/topBar/RenderModeAwareTopBar.js";
import { RenderModeAwareDashboardSidebar } from "../DashboardSidebar/RenderModeAwareDashboardSidebar.js";
import { defaultDashboardThemeModifier } from "../defaultDashboardThemeModifier.js";
import { useDashboard } from "../hooks/useDashboard.js";
import { DashboardItemPathAndSizeProvider } from "./DashboardItemPathAndSizeContext.js";
import { DashboardLoading } from "./DashboardLoading.js";
import { DensityInitializer } from "./DensityInitializer.js";
const overlayController = OverlayController.getInstance(DASHBOARD_OVERLAYS_Z_INDEX);
function resolveCoreComponents(props) {
    return {
        ErrorComponent: props.ErrorComponent ?? DefaultError,
        LoadingComponent: props.LoadingComponent ?? DefaultLoading,
        LayoutComponent: props.LayoutComponent ?? DefaultDashboardLayout,
        ButtonBarComponent: props.ButtonBarComponent ?? DefaultButtonBar,
        MenuButtonComponent: props.MenuButtonComponent ?? DefaultMenuButton,
        TopBarComponent: props.TopBarComponent ?? RenderModeAwareTopBar,
        ToolbarComponent: props.ToolbarComponent ?? HiddenToolbar,
        TitleComponent: props.TitleComponent ?? RenderModeAwareTitle,
    };
}
function resolveDialogComponents(props) {
    return {
        ScheduledEmailDialogComponent: props.ScheduledEmailDialogComponent ?? DefaultScheduledEmailDialog,
        ScheduledEmailManagementDialogComponent: props.ScheduledEmailManagementDialogComponent ?? DefaultScheduledEmailManagementDialog,
        ShareDialogComponent: props.ShareDialogComponent ?? DefaultShareDialog,
        AlertingManagementDialogComponent: props.AlertingManagementDialogComponent ?? DefaultAlertingManagementDialogNew,
        AlertingDialogComponent: props.AlertingDialogComponent ?? DefaultAlertingDialogNew,
        SaveAsDialogComponent: props.SaveAsDialogComponent ?? DefaultSaveAsDialog,
        DashboardSettingsDialogComponent: props.DashboardSettingsDialogComponent ?? DefaultDashboardSettingsDialog,
    };
}
function resolveLayoutComponents(props) {
    return {
        FilterBarComponent: props.FilterBarComponent ?? RenderModeAwareFilterBar,
        SidebarComponent: props.SidebarComponent ?? RenderModeAwareDashboardSidebar,
        EmptyLayoutDropZoneBodyComponent: props.EmptyLayoutDropZoneBodyComponent ?? DefaultEmptyLayoutDropZoneBody,
        SaveButtonComponent: props.SaveButtonComponent ?? DefaultSaveButton,
        SettingButtonComponent: props.SettingButtonComponent ?? DefaultSettingButton,
    };
}
function resolveComponentsWithDefaults(props) {
    return {
        ...resolveCoreComponents(props),
        ...resolveDialogComponents(props),
        ...resolveLayoutComponents(props),
    };
}
function shouldUseThemeProvider(props, hasThemeProvider) {
    return Boolean(props.theme || (!hasThemeProvider && !props.disableThemeLoading));
}
/**
 * @internal
 */
export function DashboardRenderer(props) {
    const { backend, workspace, hasThemeProvider, dashboardOrRef, attributeFilterProvider, dateFilterProvider, measureValueFilterProvider, filterGroupProvider, widgetProvider, insightProvider, insightBodyProvider, insightMenuButtonProvider, dashboardContentProvider, insightMenuProvider, richTextMenuProvider, richTextMenuTitleProvider, insightMenuTitleProvider, insightWidgetComponentSet, attributeFilterComponentSet, dateFilterComponentSet, richTextProvider, visualizationSwitcherProvider, richTextWidgetComponentSet, visualizationSwitcherWidgetComponentSet, visualizationSwitcherToolbarComponentProvider, dashboardLayoutWidgetComponentSet, showAsTableButtonComponentProvider, drillDialogExportDropdownProvider, } = useDashboard(props);
    const components = resolveComponentsWithDefaults(props);
    const dashboardRender = (_jsx(BackendProvider, { backend: backend, children: _jsx(WorkspaceProvider, { workspace: workspace, children: _jsx(OverlayControllerProvider, { overlayController: overlayController, children: _jsx(DashboardStoreProvider, { backend: props.backend, workspace: props.workspace, dashboard: dashboardOrRef, persistedDashboard: props.persistedDashboard, filterContextRef: props.filterContextRef, eventHandlers: props.eventHandlers, config: props.config, permissions: props.permissions, onStateChange: props.onStateChange, onEventingInitialized: props.onEventingInitialized, additionalReduxContext: props.additionalReduxContext, customizationFns: props.customizationFns, widgetsOverlayFn: props.widgetsOverlayFn, initialTabId: props.initialTabId, children: _jsx(ExportTemplateDialogContextProvider, { children: _jsx(ExportXlsxDialogContextProvider, { children: _jsx(ExportCsvDialogContextProvider, { children: _jsx(ExportTabularPdfDialogContextProvider, { children: _jsx(DashboardCustomizationsProvider, { insightMenuItemsProvider: props.insightMenuItemsProvider, richTextMenuItemsProvider: props.richTextMenuItemsProvider, existingExportTransformFn: props.customizationFns?.existingExportTransformFn, slideConfig: props.config?.slideConfig, children: _jsx(DashboardComponentsProvider, { ErrorComponent: components.ErrorComponent, LoadingComponent: components.LoadingComponent, LayoutComponent: components.LayoutComponent, InsightComponentProvider: insightProvider, InsightBodyComponentProvider: insightBodyProvider, InsightMenuButtonComponentProvider: insightMenuButtonProvider, InsightMenuTitleComponentProvider: insightMenuTitleProvider, InsightMenuComponentProvider: insightMenuProvider, VisualizationSwitcherToolbarComponentProvider: visualizationSwitcherToolbarComponentProvider, RichTextComponentProvider: richTextProvider, RichTextMenuComponentProvider: richTextMenuProvider, RichTextMenuTitleComponentProvider: richTextMenuTitleProvider, VisualizationSwitcherComponentProvider: visualizationSwitcherProvider, WidgetComponentProvider: widgetProvider, ButtonBarComponent: components.ButtonBarComponent, MenuButtonComponent: components.MenuButtonComponent, TopBarComponent: components.TopBarComponent, ToolbarComponent: components.ToolbarComponent, TitleComponent: components.TitleComponent, ScheduledEmailDialogComponent: components.ScheduledEmailDialogComponent, ScheduledEmailManagementDialogComponent: components.ScheduledEmailManagementDialogComponent, ShareDialogComponent: components.ShareDialogComponent, AlertingManagementDialogComponent: components.AlertingManagementDialogComponent, AlertingDialogComponent: components.AlertingDialogComponent, SaveAsDialogComponent: components.SaveAsDialogComponent, DashboardAttributeFilterComponentProvider: attributeFilterProvider, DashboardDateFilterComponentProvider: dateFilterProvider, DashboardMeasureValueFilterComponentProvider: measureValueFilterProvider, DashboardFilterGroupComponentProvider: filterGroupProvider, FilterBarComponent: components.FilterBarComponent, SidebarComponent: components.SidebarComponent, InsightWidgetComponentSet: insightWidgetComponentSet, RichTextWidgetComponentSet: richTextWidgetComponentSet, VisualizationSwitcherWidgetComponentSet: visualizationSwitcherWidgetComponentSet, DashboardLayoutWidgetComponentSet: dashboardLayoutWidgetComponentSet, AttributeFilterComponentSet: attributeFilterComponentSet, DateFilterComponentSet: dateFilterComponentSet, EmptyLayoutDropZoneBodyComponent: components.EmptyLayoutDropZoneBodyComponent, SaveButtonComponent: components.SaveButtonComponent, DashboardContentComponentProvider: dashboardContentProvider, SettingButtonComponent: components.SettingButtonComponent, DashboardSettingsDialogComponent: components.DashboardSettingsDialogComponent, ShowAsTableButtonComponentProvider: showAsTableButtonComponentProvider, DrillDialogExportDropdownComponentProvider: drillDialogExportDropdownProvider, children: _jsx(DashboardConfigProvider, { menuButtonConfig: props.menuButtonConfig, children: _jsx(DndProvider, { backend: HTML5Backend, children: _jsx(LayoutResizeStateProvider, { children: _jsx(DashboardItemPathAndSizeProvider, { children: _jsxs(HoveredWidgetProvider, { children: [
                                                                    _jsx(DensityInitializer, {}), _jsx(DashboardLoading, { ...props })
                                                                ] }) }) }) }) }) }) }) }) }) }) }) }) }) }) }));
    if (shouldUseThemeProvider(props, hasThemeProvider)) {
        return (_jsx(ThemeProvider, { theme: props.theme, modifier: props.themeModifier ?? defaultDashboardThemeModifier, backend: backend, workspace: workspace, 
            // Do not remove global theme styles on unmount, if the theme is provided as a prop,
            // and the theme loading is disabled.
            // This avoids flickering of the theme, when switching between the dashboard plugin engine and the default engine.
            removeGlobalStylesOnUnmout: !props.disableThemeLoading, children: dashboardRender }));
    }
    return dashboardRender;
}
//# sourceMappingURL=DashboardRenderer.js.map