export const EdenEvents = {
    activeBlockChanged: "eden-active-block-changed",
    blockContentChanged: "eden-block-content-changed",
    blockCreated: "eden-block-created",
    blockPasted: "eden-block-pasted",
    blockRemoved: "eden-block-removed",
    contentSaved: "eden-content-saved",
    playersUpdated: "eden-players-updated",
    textFormatted: "eden-text-formatted",
    textFormatedLegacy: "eden-text-formated",
    structureNodeClicked: "eden-structure-node-clicked",
    structureNodeDoubleClicked: "eden-structure-node-double-clicked",
    structureOverredNodeChanged: "eden-structure-overred-node-changed",
    structureDraggedNodeChanged: "eden-structure-dragged-node-changed",
    structureDropChanged: "eden-structure-drop-changed",
    structureDragEnd: "eden-structure-drag-end",
};
const EVENT_ALIASES = {
    [EdenEvents.textFormatted]: [EdenEvents.textFormatedLegacy],
    [EdenEvents.textFormatedLegacy]: [EdenEvents.textFormatted],
};
const warnedLegacyEvents = new Set();
function warnLegacyEventName(name) {
    if (name !== EdenEvents.textFormatedLegacy)
        return;
    const legacyName = name;
    if (warnedLegacyEvents.has(legacyName))
        return;
    warnedLegacyEvents.add(legacyName);
    console.warn(`[eden] "${EdenEvents.textFormatedLegacy}" is deprecated. Use "${EdenEvents.textFormatted}" instead.`);
}
function relatedEventNames(name) {
    const aliases = EVENT_ALIASES[name] ?? [];
    return Array.from(new Set([name, ...aliases]));
}
export function addEdenEventListener(domain, name, callback) {
    warnLegacyEventName(name);
    relatedEventNames(name).forEach((eventName) => {
        domain.addEventListener(eventName, callback);
    });
}
export function removeEdenEventListener(domain, name, callback) {
    warnLegacyEventName(name);
    relatedEventNames(name).forEach((eventName) => {
        domain.removeEventListener(eventName, callback);
    });
}
export function fireEvent(domain, name, detail) {
    warnLegacyEventName(name);
    relatedEventNames(name).forEach((eventName) => {
        const event = new CustomEvent(eventName, {
            detail: detail ?? {},
            bubbles: true,
        });
        domain.dispatchEvent(event);
    });
}
