import { Arr, Obj } from '@ephox/katamari';
import { Attribute, SugarNode } from '@ephox/sugar';
const updatePressed = (component, ariaInfo, status) => {
    Attribute.set(component.element, 'aria-pressed', status);
    if (ariaInfo.syncWithExpanded) {
        updateExpanded(component, ariaInfo, status);
    }
};
const updateSelected = (component, ariaInfo, status) => {
    Attribute.set(component.element, 'aria-selected', status);
};
const updateChecked = (component, ariaInfo, status) => {
    Attribute.set(component.element, 'aria-checked', status);
};
const updateExpanded = (component, ariaInfo, status) => {
    Attribute.set(component.element, 'aria-expanded', status);
};
// INVESTIGATE: What other things can we derive?
const tagAttributes = {
    'button': ['aria-pressed'],
    'input:checkbox': ['aria-checked']
};
const roleAttributes = {
    button: ['aria-pressed'],
    listbox: ['aria-pressed', 'aria-expanded'],
    menuitemcheckbox: ['aria-checked'],
    menuitemradio: ['aria-checked']
};
const detectFromTag = (component) => {
    const elem = component.element;
    const rawTag = SugarNode.name(elem);
    const suffix = rawTag === 'input' && Attribute.has(elem, 'type') ? ':' + Attribute.get(elem, 'type') : '';
    return Obj.get(tagAttributes, rawTag + suffix);
};
const detectFromRole = (component) => {
    const elem = component.element;
    return Attribute.getOpt(elem, 'role').bind((role) => Obj.get(roleAttributes, role));
};
const updateAuto = (component, _ariaInfo, status) => {
    // Role has priority
    const attributes = detectFromRole(component).orThunk(() => detectFromTag(component)).getOr([]);
    Arr.each(attributes, (attr) => {
        Attribute.set(component.element, attr, status);
    });
};
export { updatePressed, updateSelected, updateChecked, updateExpanded, updateAuto };
//# sourceMappingURL=ToggleModes.js.map