var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
    if (kind === "m") throw new TypeError("Private method is not writable");
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
    return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
    if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
    if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
    return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _EdenIcon_code, _EdenIcon_svg, _EdenIcon_observer, _EdenIcon_createUse, _EdenIcon_observe, _EdenIcon_unobserve;
import { renderIcon } from "./icons";
import library from "./library";
class EdenIcon extends HTMLElement {
    constructor() {
        super();
        _EdenIcon_code.set(this, void 0);
        _EdenIcon_svg.set(this, void 0);
        _EdenIcon_observer.set(this, null);
        _EdenIcon_createUse.set(this, async () => {
            if (!__classPrivateFieldGet(this, _EdenIcon_code, "f") || !__classPrivateFieldGet(this, _EdenIcon_svg, "f"))
                return;
            const { default: iconDefinition } = await library[__classPrivateFieldGet(this, _EdenIcon_code, "f")]();
            __classPrivateFieldGet(this, _EdenIcon_svg, "f").outerHTML = renderIcon(iconDefinition);
            __classPrivateFieldSet(this, _EdenIcon_svg, this.querySelector("svg"), "f");
        });
        _EdenIcon_observe.set(this, () => {
            if (!__classPrivateFieldGet(this, _EdenIcon_svg, "f"))
                return;
            const isCompatible = "IntersectionObserver" in window;
            if (!isCompatible) {
                return __classPrivateFieldGet(this, _EdenIcon_createUse, "f").call(this);
            }
            const callback = ([entry]) => {
                if (entry.isIntersecting) {
                    __classPrivateFieldGet(this, _EdenIcon_createUse, "f").call(this);
                    __classPrivateFieldGet(this, _EdenIcon_unobserve, "f").call(this);
                }
            };
            __classPrivateFieldSet(this, _EdenIcon_observer, new IntersectionObserver(callback, { rootMargin: "24px" }), "f");
            __classPrivateFieldGet(this, _EdenIcon_observer, "f").observe(__classPrivateFieldGet(this, _EdenIcon_svg, "f"));
        });
        _EdenIcon_unobserve.set(this, () => {
            if (!__classPrivateFieldGet(this, _EdenIcon_observer, "f"))
                return;
            __classPrivateFieldGet(this, _EdenIcon_observer, "f").disconnect();
            __classPrivateFieldSet(this, _EdenIcon_observer, null, "f");
        });
        __classPrivateFieldSet(this, _EdenIcon_code, this.getAttribute("code"), "f");
        this.innerHTML = `<svg viewBox="0 0 24 24"></svg>`;
        __classPrivateFieldSet(this, _EdenIcon_svg, this.querySelector("svg"), "f");
    }
    attributeChangedCallback(name, oldValue, newValue) {
        if (name === "code" && oldValue && oldValue !== newValue) {
            __classPrivateFieldSet(this, _EdenIcon_code, newValue, "f");
            __classPrivateFieldGet(this, _EdenIcon_unobserve, "f").call(this);
            __classPrivateFieldGet(this, _EdenIcon_createUse, "f").call(this);
        }
    }
    connectedCallback() {
        __classPrivateFieldGet(this, _EdenIcon_observe, "f").call(this);
    }
    disconnectedCallback() {
        __classPrivateFieldGet(this, _EdenIcon_unobserve, "f").call(this);
    }
}
_EdenIcon_code = new WeakMap(), _EdenIcon_svg = new WeakMap(), _EdenIcon_observer = new WeakMap(), _EdenIcon_createUse = new WeakMap(), _EdenIcon_observe = new WeakMap(), _EdenIcon_unobserve = new WeakMap();
EdenIcon.observedAttributes = ["code"];
if (!customElements.get("eden-icon")) {
    window.customElements.define("eden-icon", EdenIcon);
}
