"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const namespaceURI_1 = require("../../../../client/component/namespaceURI");
const ensureIcon_1 = require("../../../../client/ensureIcon");
const svg_1 = require("../../../../client/svg");
class Icon extends svg_1.SVGElement_ {
    constructor($props, $system) {
        super($props, $system, $system.api.document.createElementNS(namespaceURI_1.namespaceURI, 'svg'), $system.style['icon']);
        let { className, icon, x, y, width, height, tabIndex } = $props;
        const { title } = this.$props;
        if (className) {
            this.$element.classList.add(className);
        }
        if (x !== undefined) {
            this.$element.setAttribute('x', `${x}`);
        }
        if (y !== undefined) {
            this.$element.setAttribute('y', `${y}`);
        }
        if (width !== undefined) {
            this.$element.setAttribute('width', `${width}`);
        }
        if (height !== undefined) {
            this.$element.setAttribute('height', `${height}`);
        }
        if (tabIndex !== undefined) {
            this.$element.tabIndex = tabIndex;
        }
        if (title) {
            const title_el = this.$system.api.document.createElementNS(namespaceURI_1.namespaceURI, 'title');
            title_el.innerHTML = title;
            this.$element.appendChild(title_el);
        }
        const icon_sprite_el = this.$system.api.document.createElementNS(namespaceURI_1.namespaceURI, 'use');
        icon_sprite_el.setAttribute('href', `#${icon}`);
        this.$element.appendChild(icon_sprite_el);
        if (icon !== undefined) {
            (0, ensureIcon_1.ensureIcon)(this.$system, icon);
        }
        this.$propHandler = {
            ...this.$propHandler,
            icon: (icon = '') => {
                (0, ensureIcon_1.ensureIcon)(this.$system, icon);
                icon_sprite_el.setAttribute('href', `#${icon}`);
            },
        };
    }
}
exports.default = Icon;
//# sourceMappingURL=Component.js.map