const componentOnReady = (el, callback) => {
    if (el.componentOnReady) {
        el.componentOnReady().then((resolvedEl) => callback(resolvedEl));
    }
    else {
        raf(() => callback(el));
    }
};
const inheritAttributes = (el, attributes = []) => {
    const attributeObject = {};
    attributes.forEach((attr) => {
        if (el.hasAttribute(attr)) {
            const value = el.getAttribute(attr);
            if (value !== null) {
                attributeObject[attr] = el.getAttribute(attr);
            }
            el.removeAttribute(attr);
        }
    });
    return attributeObject;
};
const ariaAttributes = [
    'role',
    'aria-activedescendant',
    'aria-atomic',
    'aria-autocomplete',
    'aria-braillelabel',
    'aria-brailleroledescription',
    'aria-busy',
    'aria-checked',
    'aria-colcount',
    'aria-colindex',
    'aria-colindextext',
    'aria-colspan',
    'aria-controls',
    'aria-current',
    'aria-describedby',
    'aria-description',
    'aria-details',
    'aria-disabled',
    'aria-errormessage',
    'aria-expanded',
    'aria-flowto',
    'aria-haspopup',
    'aria-hidden',
    'aria-invalid',
    'aria-keyshortcuts',
    'aria-label',
    'aria-labelledby',
    'aria-level',
    'aria-live',
    'aria-multiline',
    'aria-multiselectable',
    'aria-orientation',
    'aria-owns',
    'aria-placeholder',
    'aria-posinset',
    'aria-pressed',
    'aria-readonly',
    'aria-relevant',
    'aria-required',
    'aria-roledescription',
    'aria-rowcount',
    'aria-rowindex',
    'aria-rowindextext',
    'aria-rowspan',
    'aria-selected',
    'aria-setsize',
    'aria-sort',
    'aria-valuemax',
    'aria-valuemin',
    'aria-valuenow',
    'aria-valuetext',
];
const inheritAriaAttributes = (el, ignoreList) => {
    let attributesToInherit = ariaAttributes;
    return inheritAttributes(el, attributesToInherit);
};
const raf = (h) => {
    if (typeof __zone_symbol__requestAnimationFrame === 'function') {
        return __zone_symbol__requestAnimationFrame(h);
    }
    if (typeof requestAnimationFrame === 'function') {
        return requestAnimationFrame(h);
    }
    return setTimeout(h);
};
function getDeepActiveElement(root = document) {
    let activeElement = root.activeElement;
    if (!activeElement) {
        return null;
    }
    while (activeElement?.shadowRoot) {
        const next = activeElement.shadowRoot.activeElement;
        if (!next) {
            break;
        }
        activeElement = next;
    }
    return activeElement;
}
function canReceiveFocus(el) {
    if (!el)
        return false;
    return (el instanceof HTMLElement && el.tabIndex >= 0 && !el.hasAttribute('disabled') && el.getAttribute('aria-hidden') !== 'true' && el.checkVisibility() && el.offsetParent !== null);
}
function findFormByRef(form, el) {
    if (form instanceof HTMLFormElement) {
        return form;
    }
    if (typeof form === 'string') {
        const el = document.getElementById(form);
        if (el) {
            if (el instanceof HTMLFormElement) {
                return el;
            }
            else {
                console.warn(`No Form found with selector: "#${form}". Verify that the element with id exists and is actually a <form> element.`, el);
                return null;
            }
        }
        else {
            console.warn(`No Form found with selector: "#${form}". Verify that the id is correct and the form is rendered in the DOM.`, el);
            return null;
        }
    }
    if (form !== undefined) {
        console.warn(`The provided "form" element is invalid. Verify that the form is a HTMLFormElement and rendered in the DOM.`, el);
        return null;
    }
    return el.closest('form');
}

export { canReceiveFocus as a, componentOnReady as c, findFormByRef as f, getDeepActiveElement as g, inheritAriaAttributes as i };
