/*
 * 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 { subscribeDOM } from '@kano/common/index.js';
import { DOMPart } from '../dom/dom.js';
import { part, component } from '../../decorators.js';
import { transformLegacySlider } from './legacy.js';
import { SliderComponent } from './slider-component.js';
let SliderPart = class SliderPart extends DOMPart {
    constructor() {
        super();
        this.core = this._components.get('core');
        subscribeDOM(this._el, 'input', () => {
            if (!this.core) {
                return;
            }
            this.core.value = parseInt(this._el.value, 10);
            this.core.changed.fire();
            this.core.invalidate();
        }, this, this.subscriptions);
        this.core.invalidate();
    }
    static transformLegacy(app) {
        transformLegacySlider(app);
    }
    getElement() {
        const el = document.createElement('input');
        el.title = 'slider';
        el.setAttribute('type', 'range');
        return el;
    }
    render() {
        super.render();
        if (!this.core.invalidated) {
            return;
        }
        this._el.value = this.core.value.toString();
        this.core.apply();
    }
    get value() {
        return this.core.value;
    }
    set value(v) {
        v = Math.max(0, Math.min(100, v));
        this.core.value = v;
        this.core.invalidate();
    }
    onChange(callback) {
        this.core.changed.event(callback, null, this.userSubscriptions);
    }
};
__decorate([
    component(SliderComponent)
], SliderPart.prototype, "core", void 0);
SliderPart = __decorate([
    part('slider')
], SliderPart);
export { SliderPart };
//# sourceMappingURL=slider.js.map