/**
 * @license
 * Copyright 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(element) {
        const shadowRoot = this._component.shadowRoot;
        shadowRoot.querySelectorAll(':not(style)').forEach(child => child.remove());
        if (element) {
            if (this._component.viewbox) {
                element.setAttribute('viewBox', this._component.viewbox);
            }
            element.setAttribute('aria-hidden', 'true');
            shadowRoot.appendChild(element);
        }
    }
    setViewBox(viewBox) {
        var _a;
        const svgEl = (_a = this._component.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('svg');
        svgEl === null || svgEl === void 0 ? void 0 : svgEl.setAttribute('viewBox', viewBox);
    }
}
