import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import cx from "classnames";
import { isInsightWidget, objRefToString, } from "@gooddata/sdk-model";
import { OverlayController, OverlayControllerProvider, ScrollablePanel } from "@gooddata/sdk-ui-kit";
import { simplifyText } from "@gooddata/util";
import { changeInsightWidgetDescription, changeInsightWidgetVisConfiguration, } from "../../../../model/commands/insight.js";
import { useDashboardDispatch, useDashboardSelector, } from "../../../../model/react/DashboardStoreProvider.js";
import { selectSettings } from "../../../../model/store/config/configSelectors.js";
import { DASHBOARD_HEADER_OVERLAYS_Z_INDEX } from "../../../constants/zIndex.js";
import { InsightDescriptionConfig } from "./InsightDescriptionConfig/InsightDescriptionConfig.js";
import { InsightFilters } from "./InsightFilters.js";
import { InsightTitleConfig } from "./InsightTitleConfig.js";
const overlayController = OverlayController.getInstance(DASHBOARD_HEADER_OVERLAYS_Z_INDEX);
export function InsightConfiguration({ widget, enableTitleConfig = true, }) {
    const widgetRefSuffix = isInsightWidget(widget) ? simplifyText(objRefToString(widget.ref)) : "";
    const settings = useDashboardSelector(selectSettings);
    const dispatch = useDashboardDispatch();
    const classes = cx("configuration-scrollable-panel", "s-configuration-scrollable-panel", `s-visualization-${widgetRefSuffix}`);
    const defaultDescriptionConfig = {
        source: "insight",
        includeMetrics: false,
        visible: true,
    };
    return (_jsx(ScrollablePanel, { className: classes, children: _jsxs(OverlayControllerProvider, { overlayController: overlayController, children: [
                _jsx(InsightTitleConfig, { widget: widget, isHidingOfWidgetTitleEnabled: enableTitleConfig, hideTitle: widget.configuration?.hideTitle ?? false, setVisualPropsConfigurationTitle: (widget, hideTitle) => {
                        dispatch(changeInsightWidgetVisConfiguration(widget.ref, {
                            ...widget.configuration,
                            ...{ hideTitle },
                        }));
                    } }), _jsx(InsightDescriptionConfig, { widget: widget, isWidgetDescriptionEnabled: settings.enableDescriptions ?? false, descriptionConfig: widget.configuration?.description ?? defaultDescriptionConfig, setDescriptionConfiguration: (widget, config) => {
                        dispatch(changeInsightWidgetVisConfiguration(widget.ref, {
                            hideTitle: false, // hideTitle is mandatory part of config on Bear
                            ...widget.configuration,
                            description: config,
                        }));
                    }, setWidgetDescription: (widget, description) => {
                        dispatch(changeInsightWidgetDescription(widget.ref, {
                            description,
                        }));
                    } }), _jsx(InsightFilters, { widget: widget })
            ] }) }));
}
