"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const element_1 = require("../../../../client/element");
const propHandler_1 = require("../../../../client/propHandler");
const style_1 = require("../../../../client/style");
const DEFAULT_STYLE = {};
class Anchor extends element_1.Element {
    constructor($props, $system) {
        super($props, $system);
        const { href, target, id, rel = 'noreferrer', className, style, innerText, tabIndex, title, draggable, } = this.$props;
        this.$element = this.$system.api.document.createElement('a');
        if (href !== undefined) {
            this.$element.setAttribute('href', href);
        }
        if (target !== undefined) {
            this.$element.setAttribute('target', target);
        }
        if (rel !== undefined) {
            this.$element.setAttribute('rel', rel);
        }
        if (id !== undefined) {
            this.$element.id = id;
        }
        if (className !== undefined) {
            this.$element.className = className;
        }
        if (innerText) {
            this.$element.innerText = innerText;
        }
        if (tabIndex !== undefined) {
            this.$element.tabIndex = tabIndex;
        }
        if (title) {
            this.$element.title = title;
        }
        if (draggable !== undefined) {
            this.$element.setAttribute('draggable', draggable.toString());
        }
        (0, style_1.applyStyle)(this.$element, Object.assign(Object.assign({}, DEFAULT_STYLE), style));
        this._prop_handler = Object.assign(Object.assign({}, (0, propHandler_1.htmlPropHandler)(this, this.$element, DEFAULT_STYLE)), { href: (href) => {
                if (href) {
                    this.$element.href = href;
                }
                else {
                    this.$element.removeAttribute('href');
                }
            }, target: (target) => {
                if (target) {
                    this.$element.target = target;
                }
                else {
                    this.$element.removeAttribute('target');
                }
            } });
    }
    onPropChanged(prop, current) {
        this._prop_handler[prop](current);
    }
}
exports.default = Anchor;
//# sourceMappingURL=Component.js.map