/*
  Simple string replacement utility.
  Find all instances of "___" in the string
  and replace with each string in the list of data.
  eg:
    template = 'Today is ___ and the weather is ___.'
    data = ['Friday', 'sunnny']
    --------------------------
    <- 'Today is Friday and the weather is sunny.'
*/
export function replaceWithEach(template, data) {
    let i = 0;
    return template.replace(/_{3}/g, () => (i < data.length ? data[i++] : '___'));
}
export function announce(message, data) {
    let container = document.getElementById('aria-live-container');
    if (!container) {
        container = document.createElement('div');
        container.setAttribute('id', 'aria-live-container');
        document.body.appendChild(container);
    }
    const status = document.createElement('div');
    const id = 'speak-' + Date.now();
    status.setAttribute('id', id);
    status.setAttribute('aria-atomic', 'true');
    status.setAttribute('aria-live', 'polite');
    status.style.cssText =
        'position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;';
    if (data && data.length) {
        message = replaceWithEach(`${message}`, data);
    }
    container.appendChild(status);
    setTimeout(() => {
        const liveRegion = document.getElementById(id);
        if (liveRegion)
            liveRegion.innerHTML = message;
    }, 150);
    if (window.BRIGHTSPOT?.ariaDebug === true) {
        console.log(`ARIA Announced: "${message}"`);
    }
    setTimeout(() => {
        document.getElementById(id)?.remove();
    }, 2000);
}
//# sourceMappingURL=aria.js.map