let remainingImages;
export async function waitUntilImagesDone() {
    let tries = 1000;
    while (tries > 0) {
        tries--;
        if (remainingImages === 0) {
            return;
        }
        else {
            await new Promise(resolve => setTimeout(resolve, 100));
        }
    }
    throw Error('Images not loaded');
}
export function updateLargeImageWarnings(answer) {
    const images = (answer === null || answer === void 0 ? void 0 : answer.querySelectorAll('img')) || [];
    remainingImages = images.length;
    images.forEach(img => {
        if (img.complete) {
            setTimeout(() => updateImageStatus(img), 0);
        }
        else {
            img.addEventListener('load', () => updateImageStatus(img));
        }
    });
}
function updateImageStatus(img) {
    remainingImages--;
    const wrapper = img.parentElement;
    const nextSibling = wrapper === null || wrapper === void 0 ? void 0 : wrapper.nextSibling;
    const hasFullSizeLink = nextSibling instanceof HTMLElement && nextSibling.classList.contains('full-size-image');
    const isLargeImage = img.naturalWidth > img.width;
    wrapper === null || wrapper === void 0 ? void 0 : wrapper.classList.toggle('e-large-image', isLargeImage);
    if (isLargeImage) {
        if (!hasFullSizeLink) {
            wrapper === null || wrapper === void 0 ? void 0 : wrapper.insertAdjacentHTML('afterend', `<div class="full-size-image"><a target="_blank" href="${img.src}"></a>`);
        }
    }
    else {
        if (hasFullSizeLink) {
            nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.remove();
        }
    }
}
//# sourceMappingURL=largeImageDetector.js.map