// (C) 2026 GoodData Corporation
import { useState } from "react";
import { defineMessages, useIntl } from "react-intl";
import { areObjRefsEqual } from "@gooddata/sdk-model";
const messages = defineMessages({
    added: { id: "automationParameters.announcement.added" },
    changed: { id: "automationParameters.announcement.changed" },
    removed: { id: "automationParameters.announcement.removed" },
});
/**
 * Owns the parameter screen-reader announcement string and how a parameter is named (its title, or
 * its identifier as fallback). Callers pass the relevant list and the acted-on ref.
 *
 * @internal
 */
export function useParameterAnnouncements() {
    const intl = useIntl();
    const [parameterAnnouncement, setParameterAnnouncement] = useState("");
    return {
        parameterAnnouncement,
        announceParameterAdded: (list, ref) => setParameterAnnouncement(intl.formatMessage(messages.added, { title: parameterTitle(list, ref) })),
        announceParameterChanged: (list, ref, value) => setParameterAnnouncement(intl.formatMessage(messages.changed, { title: parameterTitle(list, ref), value })),
        announceParameterRemoved: (list, ref) => setParameterAnnouncement(intl.formatMessage(messages.removed, { title: parameterTitle(list, ref) })),
    };
}
function parameterTitle(list, ref) {
    return list.find((parameter) => areObjRefsEqual(parameter.ref, ref))?.title ?? ref.identifier;
}
