import { Id } from '@ephox/katamari';
import { Attribute, PredicateFind, SelectorFind, SugarNode, SugarShadowDom } from '@ephox/sugar';
const attribute = 'aria-controls';
const find = (queryElem) => {
    const dependent = PredicateFind.closest(queryElem, (elem) => {
        if (!SugarNode.isElement(elem)) {
            return false;
        }
        const id = Attribute.get(elem, 'id');
        return id !== undefined && id.indexOf(attribute) > -1;
    });
    return dependent.bind((dep) => {
        const id = Attribute.get(dep, 'id');
        const dos = SugarShadowDom.getRootNode(dep);
        return SelectorFind.descendant(dos, `[${attribute}="${id}"]`);
    });
};
const manager = () => {
    const ariaId = Id.generate(attribute);
    const link = (elem) => {
        Attribute.set(elem, attribute, ariaId);
    };
    const unlink = (elem) => {
        Attribute.remove(elem, attribute);
    };
    return {
        id: ariaId,
        link,
        unlink,
    };
};
export { find, manager };
//# sourceMappingURL=AriaControls.js.map