/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { BaseAdapter } from '../core';
import { ICON_CONSTANTS } from './icon-constants';
export class IconAdapter extends BaseAdapter {
    constructor(component) {
        super(component);
    }
    canLazyLoad() {
        return !!window.IntersectionObserver;
    }
    observeVisibility(listener) {
        this._observer = new IntersectionObserver(entries => {
            if (entries.some(entry => entry.isIntersecting)) {
                this.destroyVisibilityObserver();
                listener();
            }
        }, { rootMargin: `${ICON_CONSTANTS.numbers.LAZY_ROOT_MARGIN}px` });
        this._observer.observe(this._component);
    }
    destroyVisibilityObserver() {
        if (this._observer) {
            this._observer.disconnect();
            this._observer = undefined;
        }
    }
    setContent(content) {
        var _a;
        const shadowRoot = this._component.shadowRoot;
        const styleTag = shadowRoot.querySelector('style');
        shadowRoot.innerHTML = content;
        if (content) {
            (_a = shadowRoot.firstElementChild) === null || _a === void 0 ? void 0 : _a.setAttribute('aria-hidden', 'true');
        }
        if (styleTag) {
            shadowRoot.appendChild(styleTag);
        }
    }
}
