import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2020-2026 GoodData Corporation
import { useMemo } from "react";
import { useIntl } from "react-intl";
import { useDashboardComponentsContext } from "../../dashboardContexts/DashboardComponentsContext.js";
/**
 * @internal
 */
export function DashboardInsight(props) {
    const { insight, widget } = props;
    const intl = useIntl();
    const { InsightWidgetComponentSet, ErrorComponent } = useDashboardComponentsContext();
    const InsightComponent = useMemo(() => (insight ? InsightWidgetComponentSet.MainComponentProvider(insight, widget) : null), [InsightWidgetComponentSet, insight, widget]);
    if (!insight || !InsightComponent) {
        return (_jsx(ErrorComponent, { code: "404", message: intl.formatMessage({ id: "widget.error.missing_insight.message" }), description: intl.formatMessage({ id: "widget.error.missing_insight.description" }) }));
    }
    return _jsx(InsightComponent, { ...props, insight: insight });
}
