import { jsx as _jsx } from "react/jsx-runtime";
// (C) 2020-2026 GoodData Corporation
import { useCallback } from "react";
import { insightTitle } from "@gooddata/sdk-model";
import { changeInsightWidgetHeader } from "../../../../model/commands/insight.js";
import { useDashboardDispatch } from "../../../../model/react/DashboardStoreProvider.js";
import { DashboardItemHeadlineContainer } from "../../../presentationComponents/DashboardItems/DashboardItemHeadlineContainer.js";
import { EditableHeadline } from "../../common/EditableHeadline.js";
const MAX_VISUALIZATION_TITLE_LENGTH = 200;
export function EditableDashboardInsightWidgetHeader({ widget, insight, clientHeight, }) {
    const dispatch = useDashboardDispatch();
    const onWidgetTitleChanged = useCallback((newTitle) => {
        if (newTitle) {
            dispatch(changeInsightWidgetHeader(widget.ref, { title: newTitle }));
        }
        else if (insight) {
            dispatch(changeInsightWidgetHeader(widget.ref, { title: insightTitle(insight) }));
        }
    }, [dispatch, insight, widget.ref]);
    const maxLength = Math.max(widget.title.length, MAX_VISUALIZATION_TITLE_LENGTH);
    return (_jsx(DashboardItemHeadlineContainer, { clientHeight: clientHeight, children: _jsx(EditableHeadline, { text: widget.title, originalTitle: widget.title, maxLength: maxLength, onTitleChange: onWidgetTitleChanged }) }));
}
//# sourceMappingURL=EditableDashboardInsightWidgetHeader.js.map