// (C) 2022-2026 GoodData Corporation
import { useCallback, useMemo } from "react";
import { idRef } from "@gooddata/sdk-model";
import { useBackendStrict, useWorkspaceStrict } from "@gooddata/sdk-ui";
import { useThemeIsLoading } from "@gooddata/sdk-ui-theme-provider";
import { DefaultDashboardAttributeFilter } from "../../filterBar/attributeFilter/DefaultDashboardAttributeFilter.js";
import { DefaultDashboardAttributeFilterComponentSetFactory } from "../../filterBar/attributeFilter/DefaultDashboardAttributeFilterComponentSetFactory.js";
import { DefaultDashboardDateFilter } from "../../filterBar/dateFilter/DefaultDashboardDateFilter.js";
import { DefaultDashboardDateFilterComponentSetFactory } from "../../filterBar/dateFilter/DefaultDashboardDateFilterComponentSetFactory.js";
import { DefaultDashboardFilterGroup } from "../../filterBar/filterBar/DefaultDashboardFilterGroup.js";
import { DefaultDashboardMeasureValueFilter } from "../../filterBar/measureValueFilter/DefaultDashboardMeasureValueFilter.js";
import { DefaultDashboardLayout as DefaultDashboardNestedLayout } from "../../widget/dashboardLayout/DefaultDashboardLayout.js";
import { DefaultDashboardLayoutComponentSetFactory } from "../../widget/dashboardLayout/DefaultDashboardLayoutComponentSetFactory.js";
import { DefaultDashboardInsight } from "../../widget/insight/DefaultDashboardInsight.js";
import { DefaultDashboardInsightComponentSetFactory } from "../../widget/insight/DefaultDashboardInsightComponentSetFactory.js";
import { DefaultInsightBody } from "../../widget/insight/DefaultInsightBody/DefaultInsightBody.js";
import { DefaultDrillDialogExportDropdown } from "../../widget/insight/ViewModeDashboardInsight/InsightDrillDialog/DefaultDrillDialogExportDropdown.js";
import { DefaultDashboardInsightMenu } from "../../widget/insightMenu/DefaultDashboardInsightMenu/DefaultDashboardInsightMenu.js";
import { DefaultDashboardInsightMenuButton } from "../../widget/insightMenu/DefaultDashboardInsightMenu/DefaultDashboardInsightMenuButton.js";
import { DefaultDashboardInsightMenuTitle } from "../../widget/insightMenu/DefaultDashboardInsightMenu/DefaultDashboardInsightMenuTitle.js";
import { DefaultDashboardRichText } from "../../widget/richText/DefaultDashboardRichText.js";
import { DefaultDashboardRichTextComponentSetFactory } from "../../widget/richText/DefaultDashboardRichTextComponentSetFactory.js";
import { DefaultDashboardRichTextMenu } from "../../widget/richTextMenu/DefaultDashboardRichTextMenu/DefaultDashboardRichTextMenu.js";
import { DefaultDashboardRichTextMenuTitle } from "../../widget/richTextMenu/DefaultDashboardRichTextMenu/DefaultDashboardRichTextMenuTitle.js";
import { DefaultShowAsTableButton } from "../../widget/showAsTableButton/DefaultShowAsTableButton/DefaultShowAsTableButton.js";
import { DefaultVisualizationSwitcherToolbar } from "../../widget/visualizationSwitcher/configuration/DefaultVisualizationSwitcherToolbar.js";
import { DefaultDashboardVisualizationSwitcher } from "../../widget/visualizationSwitcher/DefaultDashboardVisualizationSwitcher.js";
import { DefaultDashboardVisualizationSwitcherComponentSetFactory } from "../../widget/visualizationSwitcher/DefaultDashboardVisualizationSwitcherComponentSetFactory.js";
import { DefaultDashboardWidget } from "../../widget/widget/DefaultDashboardWidget.js";
import { DefaultDashboardMainContent } from "../DefaultDashboardContent/DefaultDashboardMainContent.js";
export const useDashboard = (props) => {
    const { dashboard, DashboardAttributeFilterComponentProvider, DashboardDateFilterComponentProvider, DashboardMeasureValueFilterComponentProvider, DashboardFilterGroupComponentProvider, WidgetComponentProvider, InsightComponentProvider, InsightBodyComponentProvider, InsightMenuButtonComponentProvider, InsightMenuComponentProvider, InsightMenuTitleComponentProvider, InsightComponentSetProvider, DashboardContentComponentProvider, RichTextComponentProvider, RichTextMenuComponentProvider, RichTextMenuTitleComponentProvider, VisualizationSwitcherComponentProvider, VisualizationSwitcherToolbarComponentProvider, DashboardLayoutComponentProvider, ShowAsTableButtonComponentProvider, DrillDialogExportDropdownComponentProvider, } = props;
    const backend = useBackendStrict(props.backend);
    const workspace = useWorkspaceStrict(props.workspace);
    const attributeFilterProvider = useCallback((filter) => {
        const userSpecified = DashboardAttributeFilterComponentProvider?.(filter);
        return userSpecified ?? DefaultDashboardAttributeFilter;
    }, [DashboardAttributeFilterComponentProvider]);
    const filterGroupProvider = useCallback((filterGroup) => {
        const userSpecified = DashboardFilterGroupComponentProvider?.(filterGroup);
        return userSpecified ?? DefaultDashboardFilterGroup;
    }, [DashboardFilterGroupComponentProvider]);
    const dashboardContentProvider = useCallback((dashboard) => {
        const userSpecified = DashboardContentComponentProvider?.(dashboard);
        return userSpecified ?? DefaultDashboardMainContent;
    }, [DashboardContentComponentProvider]);
    const dateFilterProvider = useCallback((filter) => {
        const userSpecified = DashboardDateFilterComponentProvider?.(filter);
        return userSpecified ?? DefaultDashboardDateFilter;
    }, [DashboardDateFilterComponentProvider]);
    const measureValueFilterProvider = useCallback((filter) => {
        const userSpecified = DashboardMeasureValueFilterComponentProvider?.(filter);
        return userSpecified ?? DefaultDashboardMeasureValueFilter;
    }, [DashboardMeasureValueFilterComponentProvider]);
    const widgetProvider = useCallback((widget) => {
        const userSpecified = WidgetComponentProvider?.(widget);
        return userSpecified ?? DefaultDashboardWidget;
    }, [WidgetComponentProvider]);
    const insightProvider = useCallback((insight, widget) => {
        const userSpecified = InsightComponentProvider?.(insight, widget);
        return userSpecified ?? DefaultDashboardInsight;
    }, [InsightComponentProvider]);
    const insightBodyProvider = useCallback((insight, widget) => {
        const userSpecified = InsightBodyComponentProvider?.(insight, widget);
        return userSpecified ?? DefaultInsightBody;
    }, [InsightBodyComponentProvider]);
    const insightMenuButtonProvider = useCallback((insight, widget) => {
        const userSpecified = InsightMenuButtonComponentProvider?.(insight, widget);
        // if user customizes the items, always use the "new" default menu button
        return userSpecified ?? DefaultDashboardInsightMenuButton;
    }, [InsightMenuButtonComponentProvider]);
    const insightMenuProvider = useCallback((insight, widget) => {
        const userSpecified = InsightMenuComponentProvider?.(insight, widget);
        // if user customizes the items, always use the "new" default menu
        return userSpecified ?? DefaultDashboardInsightMenu;
    }, [InsightMenuComponentProvider]);
    const insightMenuTitleProvider = useCallback((insight, widget) => {
        const userSpecified = InsightMenuTitleComponentProvider?.(insight, widget);
        return userSpecified ?? DefaultDashboardInsightMenuTitle;
    }, [InsightMenuTitleComponentProvider]);
    const visualizationSwitcherToolbarComponentProvider = useCallback((widget) => {
        const userSpecified = VisualizationSwitcherToolbarComponentProvider?.(widget);
        return userSpecified ?? DefaultVisualizationSwitcherToolbar;
    }, [VisualizationSwitcherToolbarComponentProvider]);
    const dashboardOrRef = useMemo(() => {
        return typeof dashboard === "string" ? idRef(dashboard) : dashboard;
    }, [dashboard]);
    const insightWidgetComponentSet = useMemo(() => {
        const defaultComponentSet = DefaultDashboardInsightComponentSetFactory(insightProvider);
        return InsightComponentSetProvider
            ? InsightComponentSetProvider(defaultComponentSet)
            : defaultComponentSet;
    }, [InsightComponentSetProvider, insightProvider]);
    const attributeFilterComponentSet = useMemo(() => {
        return DefaultDashboardAttributeFilterComponentSetFactory(attributeFilterProvider);
    }, [attributeFilterProvider]);
    const dateFilterComponentSet = useMemo(() => {
        return DefaultDashboardDateFilterComponentSetFactory(dateFilterProvider);
    }, [dateFilterProvider]);
    const richTextProvider = useCallback((richText) => {
        const userSpecified = RichTextComponentProvider?.(richText);
        return userSpecified ?? DefaultDashboardRichText;
    }, [RichTextComponentProvider]);
    const richTextMenuProvider = useCallback((richText) => {
        const userSpecified = RichTextMenuComponentProvider?.(richText);
        // if user customizes the items, always use the "new" default menu
        return userSpecified ?? DefaultDashboardRichTextMenu;
    }, [RichTextMenuComponentProvider]);
    const richTextMenuTitleProvider = useCallback((widget) => {
        const userSpecified = RichTextMenuTitleComponentProvider?.(widget);
        return userSpecified ?? DefaultDashboardRichTextMenuTitle;
    }, [RichTextMenuTitleComponentProvider]);
    const richTextWidgetComponentSet = useMemo(() => {
        return DefaultDashboardRichTextComponentSetFactory(richTextProvider);
    }, [richTextProvider]);
    const visualizationSwitcherProvider = useCallback((visualizationSwitcher) => {
        const userSpecified = VisualizationSwitcherComponentProvider?.(visualizationSwitcher);
        return userSpecified ?? DefaultDashboardVisualizationSwitcher;
    }, [VisualizationSwitcherComponentProvider]);
    const visualizationSwitcherWidgetComponentSet = useMemo(() => {
        return DefaultDashboardVisualizationSwitcherComponentSetFactory(visualizationSwitcherProvider);
    }, [visualizationSwitcherProvider]);
    const dashboardLayoutProvider = useCallback((dashboardLayout) => {
        const userSpecified = DashboardLayoutComponentProvider?.(dashboardLayout);
        return userSpecified ?? DefaultDashboardNestedLayout;
    }, [DashboardLayoutComponentProvider]);
    const dashboardLayoutWidgetComponentSet = useMemo(() => {
        return DefaultDashboardLayoutComponentSetFactory(dashboardLayoutProvider);
    }, [dashboardLayoutProvider]);
    const showAsTableButtonComponentProvider = useCallback((widget) => {
        const userSpecified = ShowAsTableButtonComponentProvider?.(widget);
        return userSpecified ?? DefaultShowAsTableButton;
    }, [ShowAsTableButtonComponentProvider]);
    const drillDialogExportDropdownProvider = useCallback((insight, widget) => {
        return (DrillDialogExportDropdownComponentProvider?.(insight, widget) ??
            DefaultDrillDialogExportDropdown);
    }, [DrillDialogExportDropdownComponentProvider]);
    const isThemeLoading = useThemeIsLoading();
    const hasThemeProvider = isThemeLoading !== undefined;
    return {
        backend,
        workspace,
        hasThemeProvider,
        dashboardOrRef,
        attributeFilterProvider,
        dateFilterProvider,
        measureValueFilterProvider,
        filterGroupProvider,
        widgetProvider,
        insightProvider,
        insightBodyProvider,
        insightMenuButtonProvider,
        insightMenuProvider,
        insightMenuTitleProvider,
        dashboardContentProvider,
        insightWidgetComponentSet,
        attributeFilterComponentSet,
        dateFilterComponentSet,
        richTextProvider,
        richTextMenuProvider,
        richTextMenuTitleProvider,
        richTextWidgetComponentSet,
        visualizationSwitcherProvider,
        visualizationSwitcherWidgetComponentSet,
        visualizationSwitcherToolbarComponentProvider,
        dashboardLayoutProvider,
        dashboardLayoutWidgetComponentSet,
        showAsTableButtonComponentProvider,
        drillDialogExportDropdownProvider,
    };
};
//# sourceMappingURL=useDashboard.js.map