/**
 * @fileoverview added by tsickle
 * Generated from: lib/ui-components/tap-variable-range/tap-variable-range.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { __awaiter, __decorate, __generator, __metadata } from "tslib";
import { Component, ContentChild, Directive, EventEmitter, Input, Output, TemplateRef, } from '@angular/core';
import { CurrentDeviceService, PendingCallManager } from '@iotize/ionic';
import { AppGenComponent, AppGenField } from '../../metadata/decorators';
var ErrorContainerDirective = /** @class */ (function () {
    function ErrorContainerDirective(tpl) {
        this.tpl = tpl;
    }
    ErrorContainerDirective.decorators = [
        { type: Directive, args: [{
                    selector: '[errorContainer]'
                },] }
    ];
    /** @nocollapse */
    ErrorContainerDirective.ctorParameters = function () { return [
        { type: TemplateRef }
    ]; };
    return ErrorContainerDirective;
}());
export { ErrorContainerDirective };
if (false) {
    /** @type {?} */
    ErrorContainerDirective.prototype.tpl;
}
/*
@AppGenComponent({
  constraints: {
    isArray: 'NO',
    isNumber: 'YES'
  }
})
*/
var TapVariableRangeComponent = /** @class */ (function () {
    function TapVariableRangeComponent(tapService) {
        this.editable = true;
        this.min = 0;
        this.max = 100;
        this.step = 1;
        this.pin = true;
        this.snaps = true;
        this.ticks = true;
        this.debounce = 0;
        this.showError = true;
        this.onError = new EventEmitter();
        this.pendingCallManager = PendingCallManager.create(tapService);
    }
    Object.defineProperty(TapVariableRangeComponent.prototype, "variable", {
        set: /**
         * @param {?} variable
         * @return {?}
         */
        function (variable) {
            this._variable = variable;
            if (variable) {
                this.inputStream = variable.values;
            }
            else {
                this.inputStream = undefined;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableRangeComponent.prototype, "loading", {
        // @ContentChild(TemplateRef) puppyTemplate: TemplateRef<NgForOfContext<Puppy>>;
        get: 
        // @ContentChild(TemplateRef) puppyTemplate: TemplateRef<NgForOfContext<Puppy>>;
        /**
         * @return {?}
         */
        function () {
            return this.pendingCallManager.loading;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableRangeComponent.prototype, "pending", {
        get: /**
         * @return {?}
         */
        function () {
            return this.pendingCallManager.hasPendingCall();
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableRangeComponent.prototype, "errorContainerTemplate", {
        get: /**
         * @return {?}
         */
        function () {
            return this.errorContainerDir && this.errorContainerDir.tpl;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableRangeComponent.prototype, "errorContainerTemplateContext", {
        get: /**
         * @return {?}
         */
        function () {
            return { $implicit: this.error };
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @return {?}
     */
    TapVariableRangeComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
    };
    /**
     * @return {?}
     */
    TapVariableRangeComponent.prototype.ngOnDestroy = /**
     * @return {?}
     */
    function () {
        this.pendingCallManager.destroy();
    };
    /**
     * @return {?}
     */
    TapVariableRangeComponent.prototype.cancel = /**
     * @return {?}
     */
    function () {
        this.pendingCallManager.cancel();
        this.error = undefined;
    };
    /**
     * @param {?} newValue
     * @return {?}
     */
    TapVariableRangeComponent.prototype.onValueChanged = /**
     * @param {?} newValue
     * @return {?}
     */
    function (newValue) {
        var _this = this;
        // console.log('TapVariableRangeComponent onValueChanged', newValue);
        if (this.editable && this._variable && !this.loading) {
            this.pendingCallManager.exec((/**
             * @return {?}
             */
            function () { return __awaiter(_this, void 0, void 0, function () {
                var _a;
                return __generator(this, function (_b) {
                    switch (_b.label) {
                        case 0: return [4 /*yield*/, ((_a = this._variable) === null || _a === void 0 ? void 0 : _a.write(newValue))];
                        case 1:
                            _b.sent();
                            this.error = undefined;
                            return [2 /*return*/];
                    }
                });
            }); }))
                .catch((/**
             * @param {?} err
             * @return {?}
             */
            function (err) { return __awaiter(_this, void 0, void 0, function () {
                return __generator(this, function (_a) {
                    this._tryRestaureOldValue();
                    this._onError(err);
                    return [2 /*return*/];
                });
            }); }));
        }
    };
    /**
     * @private
     * @return {?}
     */
    TapVariableRangeComponent.prototype._tryRestaureOldValue = /**
     * @private
     * @return {?}
     */
    function () {
        if (this._variable) {
            this._variable
                .read()
                .catch((/**
             * @param {?} err
             * @return {?}
             */
            function (err) { return console.warn(err); })); // TODO handle error
        }
    };
    /**
     * @private
     * @param {?} err
     * @return {?}
     */
    TapVariableRangeComponent.prototype._onError = /**
     * @private
     * @param {?} err
     * @return {?}
     */
    function (err) {
        this.error = err;
        if (this.onError) {
            this.onError.emit(err);
        }
    };
    TapVariableRangeComponent.decorators = [
        { type: Component, args: [{
                    selector: 'tap-variable-range',
                    template: "<ion-item-sliding [disabled]=\"!error\">\r\n    <ion-item [ngStyle]=\"error && {'border-right': '#eb445a solid 5px'}\" [lines]=\"'none'\">\r\n    <monitoring-range *ngIf=\"_variable\" [disabled]=\"loading || !editable || pending\" [input-stream]=\"inputStream\" [ticks]=\"ticks\" [pin]=\"pin\" [snaps]=\"snaps\"  [max]=\"max\" [min]=\"min\" [step]=\"step\" style=\"width: 100%;\" (onValueChanged)=\"onValueChanged($event)\" >\r\n        <ng-template monitoringRangeContent>\r\n            <ion-label slot=\"start\">{{min}}</ion-label >\r\n            <ion-label slot=\"end\">{{max}}</ion-label >\r\n            <ion-button no-margin slot=\"end\" *ngIf=\"pending\" fill=\"clear\" disabled=\"true\"  color=\"warning\" >\r\n                <ion-icon name=\"alert\"></ion-icon>\r\n            </ion-button>\r\n            <ion-button no-margin slot=\"end\" *ngIf=\"pending\" fill=\"clear\" slot=\"end\" color=\"dark\" (click)=\"cancel()\">\r\n                <ion-icon name=\"close\"></ion-icon>\r\n            </ion-button>\r\n        </ng-template>\r\n    </monitoring-range>\r\n    <ion-icon slot=\"end\" *ngIf=\"error\"  name=\"alert-outline\" color=\"danger\"></ion-icon>\r\n</ion-item>\r\n    <ion-item-options side=\"end\" style=\"max-width: 85%\">\r\n      <ion-item-option color=\"danger\">\r\n        <ion-text *ngIf=\"error\" color=\"light\" style=\"max-width: 100%;\">\r\n          <span style=\"text-transform:none!important;\">{{error.message}}</span>\r\n        </ion-text>\r\n      </ion-item-option>\r\n    </ion-item-options>\r\n  </ion-item-sliding>\r\n",
                    styles: [""]
                }] }
    ];
    /** @nocollapse */
    TapVariableRangeComponent.ctorParameters = function () { return [
        { type: CurrentDeviceService }
    ]; };
    TapVariableRangeComponent.propDecorators = {
        errorContainerDir: [{ type: ContentChild, args: [ErrorContainerDirective, { static: true, read: true },] }],
        variable: [{ type: Input }],
        editable: [{ type: Input }],
        min: [{ type: Input }],
        max: [{ type: Input }],
        step: [{ type: Input }],
        pin: [{ type: Input }],
        snaps: [{ type: Input }],
        ticks: [{ type: Input }],
        debounce: [{ type: Input }],
        showError: [{ type: Input }],
        onError: [{ type: Output }]
    };
    __decorate([
        AppGenField({
            schema: {
                type: 'boolean'
            }
        }),
        __metadata("design:type", Boolean)
    ], TapVariableRangeComponent.prototype, "editable", void 0);
    __decorate([
        AppGenField({
            schema: {
                type: 'number',
                default: 0,
                description: 'Minimum value of the range.'
            }
        }),
        __metadata("design:type", Number)
    ], TapVariableRangeComponent.prototype, "min", void 0);
    __decorate([
        AppGenField({
            schema: {
                type: 'number',
                default: 100,
                description: 'Maximum value of the range.'
            }
        }),
        __metadata("design:type", Number)
    ], TapVariableRangeComponent.prototype, "max", void 0);
    __decorate([
        AppGenField({
            schema: {
                type: 'number',
                description: 'Specifies the value granularity.',
                default: 1
            }
        }),
        __metadata("design:type", Number)
    ], TapVariableRangeComponent.prototype, "step", void 0);
    __decorate([
        AppGenField({
            schema: {
                type: 'boolean',
                default: true,
                description: "Show pin above slider with currently selected value\n   It's only available for integer values (float values will be rounded)."
            }
        }),
        __metadata("design:type", Boolean)
    ], TapVariableRangeComponent.prototype, "pin", void 0);
    __decorate([
        AppGenField({
            schema: {
                type: 'boolean',
                default: true,
                description: "If true, the knob snaps to tick marks evenly spaced based on the step property value."
            }
        }),
        __metadata("design:type", Boolean)
    ], TapVariableRangeComponent.prototype, "snaps", void 0);
    __decorate([
        AppGenField({
            schema: {
                type: 'boolean',
                default: true,
                description: 'If true, tick marks are displayed based on the step value. Only applies when snaps is true.'
            }
        }),
        __metadata("design:type", Boolean)
    ], TapVariableRangeComponent.prototype, "ticks", void 0);
    __decorate([
        AppGenField({
            schema: {
                type: 'integer',
                default: 0,
                description: 'How long, in milliseconds, to wait to trigger the change event after each change in the range value.'
            }
        }),
        __metadata("design:type", Number)
    ], TapVariableRangeComponent.prototype, "debounce", void 0);
    /*
    @AppGenComponent({
      constraints: {
        isArray: 'NO',
        isNumber: 'YES'
      }
    })
    */
    TapVariableRangeComponent = __decorate([
        AppGenComponent({
            constraints: {
                isArray: 'YES',
                isNumber: 'YES'
            }
        }),
        __metadata("design:paramtypes", [CurrentDeviceService])
    ], TapVariableRangeComponent);
    return TapVariableRangeComponent;
}());
export { TapVariableRangeComponent };
if (false) {
    /** @type {?} */
    TapVariableRangeComponent.prototype.errorContainerDir;
    /** @type {?} */
    TapVariableRangeComponent.prototype.editable;
    /** @type {?} */
    TapVariableRangeComponent.prototype.min;
    /** @type {?} */
    TapVariableRangeComponent.prototype.max;
    /** @type {?} */
    TapVariableRangeComponent.prototype.step;
    /** @type {?} */
    TapVariableRangeComponent.prototype.pin;
    /** @type {?} */
    TapVariableRangeComponent.prototype.snaps;
    /** @type {?} */
    TapVariableRangeComponent.prototype.ticks;
    /** @type {?} */
    TapVariableRangeComponent.prototype.debounce;
    /** @type {?} */
    TapVariableRangeComponent.prototype.showError;
    /** @type {?} */
    TapVariableRangeComponent.prototype.onError;
    /** @type {?} */
    TapVariableRangeComponent.prototype.error;
    /** @type {?} */
    TapVariableRangeComponent.prototype.pendingCallManager;
    /** @type {?} */
    TapVariableRangeComponent.prototype.inputStream;
    /** @type {?} */
    TapVariableRangeComponent.prototype._variable;
}
//# sourceMappingURL=data:application/json;base64, 