var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var ButtonPart_1;
import { button } from '@kano/styles/button.js';
import { DOMPart } from '../dom/dom.js';
import { part, component } from '../../decorators.js';
import { transformLegacyButton } from './legacy.js';
import { ButtonComponent } from './button-component.js';
let ButtonPart = ButtonPart_1 = class ButtonPart extends DOMPart {
    constructor() {
        super();
        this.core = this._components.get('core');
        this.core.invalidate();
    }
    /**
     * Adds the button styles to a given DOM element
     * @param root Target DOM element for the styles to be added to
     */
    static addStyles(root) {
        // Only add once
        if (ButtonPart_1.stylesAdded) {
            return;
        }
        root.appendChild(button.content.cloneNode(true));
    }
    static transformLegacy(app) {
        transformLegacyButton(app);
    }
    onInstall(context) {
        super.onInstall(context);
        ButtonPart_1.addStyles(context.dom.root);
    }
    getElement() {
        const el = document.createElement('button');
        el.classList.add('btn');
        el.title = 'button';
        return el;
    }
    render() {
        super.render();
        if (this.core && this.core.invalidated) {
            this._el.textContent = this.core.label;
            this._el.style.backgroundColor = this.core.backgroundColor;
            this._el.style.color = this.core.textColor;
            this.core.apply();
        }
    }
    get label() {
        return this.core.label;
    }
    set label(label) {
        this.core.label = label;
        this.core.invalidate();
        this.updateSize();
    }
    set color(color) {
        this.core.textColor = color;
        this.core.invalidate();
    }
    get color() {
        return this.core.textColor;
    }
    set background(c) {
        this.core.backgroundColor = c;
        this.core.invalidate();
    }
    get background() {
        return this.core.backgroundColor;
    }
};
ButtonPart.stylesAdded = false;
__decorate([
    component(ButtonComponent)
], ButtonPart.prototype, "core", void 0);
ButtonPart = ButtonPart_1 = __decorate([
    part('button')
], ButtonPart);
export { ButtonPart };
//# sourceMappingURL=button.js.map