import { buttonsMap } from '../models/editor-model';
import { handleFocusEvents } from '../utils/focus';

/** Adds aria attributes for the menu buttons
 *  This is an accessibility fix that is called
 *  on menu load.
 */
export function addAccessibilityToButtons() {
	const helpId = 'Help';
	const helpElement = document.querySelector('[title="Help"]');
	if (helpElement) {
		helpElement.setAttribute('id', helpId.toLowerCase());
		helpElement.setAttribute('aria-label', helpId);
		handleFocusEvents(helpElement);
	}
	buttonsMap.forEach((value: string, key: string) => {
		const element = document.querySelector(`.${value}`);
		if (element) {
			const tooltip = key.toLowerCase().replace(' ', '-');
			element.setAttribute('id', tooltip);
			element.setAttribute('aria-label', tooltip);
			handleFocusEvents(element);
		}
	});
}
