import { __esDecorate, __runInitializers } from "tslib";
/*
Copyright 2022 Pawel Psztyc
Licensed under the CC-BY 2.0
*/
import { html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
import * as Icons from '../Icons.js';
let UiIcon = (() => {
    let _classSuper = LitElement;
    let _icon_decorators;
    let _icon_initializers = [];
    let _icon_extraInitializers = [];
    return class UiIcon extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _icon_decorators = [property()];
            __esDecorate(this, null, _icon_decorators, { kind: "accessor", name: "icon", static: false, private: false, access: { has: obj => "icon" in obj, get: obj => obj.icon, set: (obj, value) => { obj.icon = value; } }, metadata: _metadata }, _icon_initializers, _icon_extraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        hasIconInternal = false;
        iconValue;
        #icon_accessor_storage = __runInitializers(this, _icon_initializers, void 0);
        /**
         * An icon to be rendered from the ApiIcons library.
         * When incorrect icon is referenced nothing is rendered.
         * @attribute
         */
        get icon() { return this.#icon_accessor_storage; }
        set icon(value) { this.#icon_accessor_storage = value; }
        /**
         * @returns True when the icon was found and is rendered.
         */
        get hasIcon() {
            return this.hasIconInternal;
        }
        connectedCallback() {
            super.connectedCallback();
            const ariaHidden = this.getAttribute('aria-hidden');
            if (ariaHidden === 'false') {
                // Allow the user to set `aria-hidden="false"` to create an icon that is
                // announced by screen readers.
                this.removeAttribute('aria-hidden');
                return;
            }
            // Needed for VoiceOver, which will create a "group" if the element is a
            // sibling to other content.
            this.setAttribute('aria-hidden', 'true');
        }
        willUpdate(cp) {
            if (cp.has('icon')) {
                this.updateIcon(this.icon);
            }
        }
        /**
         * Maps icon name to it's definition and sets `hasIcon` value.
         *
         * @param name Icon name
         */
        updateIcon(name) {
            const icon = Icons[name];
            this.hasIconInternal = !!icon;
            this.iconValue = icon;
            this.requestUpdate();
        }
        /**
         * @return Template result for an icon
         */
        render() {
            const { hasIcon, iconValue } = this;
            if (!hasIcon) {
                return html `<slot></slot>`;
            }
            return html `${iconValue}`;
        }
        constructor() {
            super(...arguments);
            __runInitializers(this, _icon_extraInitializers);
        }
    };
})();
export default UiIcon;
//# sourceMappingURL=Icon.js.map