/*
 * Copyright (C) 2016-2020 Kano Computing Ltd.
 * License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 */
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;
};
import { DOMPart } from '../dom/dom.js';
import { part, component } from '../../decorators.js';
import { subscribeDOM } from '@kano/common/index.js';
import { transformLegacyTextInput } from './legacy.js';
import { TextInputComponent } from './text-input-component.js';
let TextInputPart = class TextInputPart extends DOMPart {
    constructor() {
        super();
        this.core = this._components.get('core');
        subscribeDOM(this._el, 'input', () => {
            if (!this.core) {
                return;
            }
            this.core.value = this._el.value;
            this.core.change.fire();
        }, this, this.subscriptions);
        this.core.invalidate();
    }
    static transformLegacy(app) {
        transformLegacyTextInput(app);
    }
    getElement() {
        const el = document.createElement('input');
        el.title = 'text-input';
        return el;
    }
    render() {
        super.render();
        if (!this.core.invalidated) {
            return;
        }
        this._el.value = this.core.value;
        this._el.placeholder = this.core.placeholder;
        this.core.apply();
    }
    get value() {
        return this.core.value;
    }
    set value(v) {
        this.core.value = v;
        this.core.invalidate();
    }
    get placeholder() {
        return this.core.placeholder;
    }
    set placeholder(p) {
        this.core.placeholder = p;
        this.core.invalidate();
    }
    onChange(callback) {
        this.core.change.event(callback, null, this.userSubscriptions);
    }
};
__decorate([
    component(TextInputComponent)
], TextInputPart.prototype, "core", void 0);
TextInputPart = __decorate([
    part('text-input')
], TextInputPart);
export { TextInputPart };
//# sourceMappingURL=text-input.js.map