import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { useDashboardSelector } from "../../../model/react/DashboardStoreProvider.js";
import { selectDashboardLoading } from "../../../model/store/loading/loadingSelectors.js";
import { useDashboardComponentsContext } from "../../dashboardContexts/DashboardComponentsContext.js";
import { useDashboardExportData } from "../../export/useExportData.js";
import { DashboardInner } from "./DashboardInner.js";
export function DashboardLoading(props) {
    const { loading, error, result } = useDashboardSelector(selectDashboardLoading);
    const { ErrorComponent, LoadingComponent } = useDashboardComponentsContext();
    // The render mode and the settings are set in the store only after the dashboard
    // initialization finishes, so both must be read from the config here.
    const isEarlyExportStatusEnabled = Boolean(props.config?.settings?.enableExportTimeoutFix);
    const exportData = useDashboardExportData(isEarlyExportStatusEnabled ? props.config?.initialRenderMode : undefined, "loading", "root");
    if (error) {
        return _jsx(ErrorComponent, { message: error.message });
    }
    if (loading || !result) {
        // In export mode, emit the loading export status right away so that the exporter
        // can tell the rendering has started even before any dashboard data is loaded.
        // The element is a hidden sibling (same as the gd-dashboard-meta export data),
        // so it cannot affect the layout of the loading indicator.
        return (_jsxs(_Fragment, { children: [exportData ? _jsx("div", { style: { display: "none" }, ...exportData }) : null, _jsx(LoadingComponent, {})
            ] }));
    }
    return _jsx(DashboardInner, { ...props });
}
