import { __decorate } 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';
export default class UiIcon extends LitElement {
    constructor() {
        super(...arguments);
        this.hasIconInternal = false;
    }
    /**
     * An icon to be rendered from the ApiIcons library.
     * When incorrect icon is referenced nothing is rendered.
     * @attribute
     */
    get icon() {
        return this.iconInternal;
    }
    set icon(value) {
        const old = this.iconInternal;
        if (old === value) {
            return;
        }
        this.iconInternal = value;
        this.updateIcon(value);
        // don't request update here
    }
    /**
     * @returns True when the icon was found and is rendered.
     */
    get hasIcon() {
        return this.hasIconInternal;
    }
    /**
     * 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: _iconValue } = this;
        if (!hasIcon) {
            return html `<slot></slot>`;
        }
        return html `${_iconValue}`;
    }
}
__decorate([
    property()
], UiIcon.prototype, "icon", null);
//# sourceMappingURL=UiIcon.js.map