/**
 * @fileoverview added by tsickle
 * Generated from: lib/ui-components/tap-variable-switch-picture/tap-variable-switch-picture.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { __awaiter, __decorate, __generator, __metadata } from "tslib";
import { ChangeDetectorRef, Component, Input } from '@angular/core';
import { CurrentDeviceService, PendingCallManager } from '@iotize/ionic';
import { Observable } from 'rxjs';
import { AppGenField } from '../../metadata/decorators';
/**
 * @record
 */
export function PictureData() { }
if (false) {
    /** @type {?} */
    PictureData.prototype.index;
    /** @type {?} */
    PictureData.prototype.src;
}
var TapVariableSwitchPictureComponent = /** @class */ (function () {
    function TapVariableSwitchPictureComponent(changeDetectorRef, tapService) {
        this.changeDetectorRef = changeDetectorRef;
        this.tapService = tapService;
        this.state = 0;
        this.loaded = false;
        this.stateText = 'State';
        this.pendingCallManager = PendingCallManager.create(tapService);
    }
    Object.defineProperty(TapVariableSwitchPictureComponent.prototype, "fieldError", {
        set: /**
         * @param {?} err
         * @return {?}
         */
        function (err) {
            this.error = err;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableSwitchPictureComponent.prototype, "pending", {
        get: /**
         * @return {?}
         */
        function () {
            return this.pendingCallManager.pendingCall !== undefined;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableSwitchPictureComponent.prototype, "variable", {
        set: /**
         * @param {?} variable
         * @return {?}
         */
        function (variable) {
            this._variable = variable;
            if (variable) {
                this.inputStream = variable.values;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableSwitchPictureComponent.prototype, "inputStream", {
        set: /**
         * @param {?} inputs
         * @return {?}
         */
        function (inputs) {
            var _this = this;
            inputs.subscribe((/**
             * @param {?} value
             * @return {?}
             */
            function (value) {
                _this.state = value;
                _this.pictures.filter((/**
                 * @param {?} value
                 * @return {?}
                 */
                function (value) {
                    if (value.index == _this.state) {
                        _this.currentSrc = value.src;
                        _this.loaded = true;
                    }
                }));
            }));
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @return {?}
     */
    TapVariableSwitchPictureComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
    };
    /**
     * @return {?}
     */
    TapVariableSwitchPictureComponent.prototype.switchPicture = /**
     * @return {?}
     */
    function () {
        var _this = this;
        if (this.editable) {
            this.state++;
            if (this.state == this.pictures.length + 1) {
                this.state = 1;
            }
            this.pictures.filter((/**
             * @param {?} value
             * @return {?}
             */
            function (value) {
                if (value.index == _this.state) {
                    _this.pendingCallManager.exec((/**
                     * @return {?}
                     */
                    function () { return __awaiter(_this, void 0, void 0, function () {
                        var _this = this;
                        var _a;
                        return __generator(this, function (_b) {
                            return [2 /*return*/, (_a = this._variable) === null || _a === void 0 ? void 0 : _a.write(value.src).then((/**
                                 * @return {?}
                                 */
                                function () {
                                    _this.changeDetectorRef.detectChanges();
                                }))];
                        });
                    }); }))
                        .catch((/**
                     * @param {?} err
                     * @return {?}
                     */
                    function (err) {
                        if (!_this.pending) {
                            _this.fieldError = err;
                        }
                        else {
                            _this.pendingSubmitValue = value.src;
                        }
                        _this.changeDetectorRef.detectChanges();
                    }));
                    _this.currentSrc = value.src;
                }
            }));
        }
    };
    TapVariableSwitchPictureComponent.decorators = [
        { type: Component, args: [{
                    selector: 'tap-variable-switch-picture',
                    template: "\r\n\r\n<ion-item-sliding [disabled]=\"!error\">\r\n  <ion-item  [ngStyle]=\"error && {'border-right': '#eb445a solid 5px'}\">\r\n    <ion-thumbnail slot=\"start\">\r\n      <img *ngIf=\"loaded\" (click)=\"switchPicture()\" [src]=\"currentSrc\">\r\n      <ion-spinner style=\"height:100%; width:100%\"   *ngIf=\"!loaded\" name=\"crescent\" color=\"primary\"></ion-spinner>\r\n    </ion-thumbnail>\r\n    <ion-label>{{stateText}} : {{state}}</ion-label>\r\n    <ion-icon slot=\"end\" *ngIf=\"error\"  name=\"alert-outline\" color=\"danger\"></ion-icon>\r\n  </ion-item>\r\n\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>",
                    styles: [""]
                }] }
    ];
    /** @nocollapse */
    TapVariableSwitchPictureComponent.ctorParameters = function () { return [
        { type: ChangeDetectorRef },
        { type: CurrentDeviceService }
    ]; };
    TapVariableSwitchPictureComponent.propDecorators = {
        fieldError: [{ type: Input }],
        pictures: [{ type: Input }],
        stateText: [{ type: Input }],
        editable: [{ type: Input }],
        variable: [{ type: Input }],
        inputStream: [{ type: Input, args: ['input',] }]
    };
    __decorate([
        AppGenField({
            schema: {
                type: 'boolean',
                default: false
            }
        }),
        __metadata("design:type", Boolean)
    ], TapVariableSwitchPictureComponent.prototype, "editable", void 0);
    return TapVariableSwitchPictureComponent;
}());
export { TapVariableSwitchPictureComponent };
if (false) {
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.state;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.currentSrc;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.pendingCallManager;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.pendingSubmitValue;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.error;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.field;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.loaded;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype._variable;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.pictures;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.stateText;
    /** @type {?} */
    TapVariableSwitchPictureComponent.prototype.editable;
    /**
     * @type {?}
     * @private
     */
    TapVariableSwitchPictureComponent.prototype.changeDetectorRef;
    /**
     * @type {?}
     * @private
     */
    TapVariableSwitchPictureComponent.prototype.tapService;
}
//# sourceMappingURL=data:application/json;base64, 