/**
 * @fileoverview added by tsickle
 * Generated from: lib/ui-components/tap-variable-date-time-picker/tap-variable-date-time-picker.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 { ToastController } from '@ionic/angular';
import { CurrentDeviceService, PendingCallManager } from '@iotize/ionic';
import { Observable } from 'rxjs';
import { AppGenComponent, AppGenField } from '../../metadata/decorators';
var TapVariableDateTimePickerComponent = /** @class */ (function () {
    function TapVariableDateTimePickerComponent(changeDetectorRef, tapService, toastController) {
        this.changeDetectorRef = changeDetectorRef;
        this.toastController = toastController;
        this.loaded = false;
        this.format = "YYYY DDDD MMM, HH:mm:ss";
        this.formatDataWrite = this.defaultDataFormatWrite;
        this.formatDataRead = this.defaultDataFormatRead;
        this.pendingCallManager = PendingCallManager.create(tapService);
    }
    Object.defineProperty(TapVariableDateTimePickerComponent.prototype, "fieldError", {
        set: /**
         * @param {?} err
         * @return {?}
         */
        function (err) {
            this.error = err;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableDateTimePickerComponent.prototype, "pending", {
        get: /**
         * @return {?}
         */
        function () {
            return this.pendingCallManager.pendingCall !== undefined;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableDateTimePickerComponent.prototype, "variable", {
        set: /**
         * @param {?} variable
         * @return {?}
         */
        function (variable) {
            this._variable = variable;
            if (variable) {
                this.inputStream = variable.values;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TapVariableDateTimePickerComponent.prototype, "inputStream", {
        set: /**
         * @param {?} inputs
         * @return {?}
         */
        function (inputs) {
            var _this = this;
            inputs.subscribe((/**
             * @param {?} value
             * @return {?}
             */
            function (value) {
                _this.dateTimeValue = _this.formatDataRead(value);
                _this.loaded = true;
            }));
        },
        enumerable: true,
        configurable: true
    });
    /**
     * @return {?}
     */
    TapVariableDateTimePickerComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
    };
    /**
     * @param {?} data
     * @return {?}
     */
    TapVariableDateTimePickerComponent.prototype.defaultDataFormatWrite = /**
     * @param {?} data
     * @return {?}
     */
    function (data) {
        return data / 1000;
    };
    /**
     * @param {?} value
     * @return {?}
     */
    TapVariableDateTimePickerComponent.prototype.defaultDataFormatRead = /**
     * @param {?} value
     * @return {?}
     */
    function (value) {
        return new Date(value * 1000).toISOString();
    };
    /**
     * @param {?} event
     * @return {?}
     */
    TapVariableDateTimePickerComponent.prototype.onChange = /**
     * @param {?} event
     * @return {?}
     */
    function (event) {
        var _this = this;
        /** @type {?} */
        var timeStamp = this.formatDataWrite(Date.parse(event.detail.value));
        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(timeStamp).then((/**
                     * @return {?}
                     */
                    function () {
                        _this.changeDetectorRef.detectChanges();
                    }))];
            });
        }); }))
            .catch((/**
         * @param {?} err
         * @return {?}
         */
        function (err) {
            if (!_this.pending) {
                _this.fieldError = err;
            }
            else {
                _this.pendingSubmitValue = timeStamp;
            }
            _this.changeDetectorRef.detectChanges();
        }));
    };
    TapVariableDateTimePickerComponent.decorators = [
        { type: Component, args: [{
                    selector: 'tap-variable-date-time-picker',
                    template: "<ion-item-sliding [disabled]=\"!error\">\r\n  <ion-item [ngStyle]=\"error && {'border-right': '#eb445a solid 5px'}\">\r\n    <ion-label *ngIf=\"label\">{{label}}</ion-label>\r\n    <ion-spinner *ngIf=\"!loaded\" name=\"crescent\" color=\"primary\"></ion-spinner>\r\n    <ion-datetime *ngIf=\"loaded\" [displayFormat]=\"format\" [value]=\"dateTimeValue\" (ionChange)=\"onChange($event)\"></ion-datetime>\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 */
    TapVariableDateTimePickerComponent.ctorParameters = function () { return [
        { type: ChangeDetectorRef },
        { type: CurrentDeviceService },
        { type: ToastController }
    ]; };
    TapVariableDateTimePickerComponent.propDecorators = {
        fieldError: [{ type: Input }],
        format: [{ type: Input }],
        label: [{ type: Input }],
        formatDataWrite: [{ type: Input }],
        formatDataRead: [{ type: Input }],
        variable: [{ type: Input }],
        inputStream: [{ type: Input, args: ['input',] }]
    };
    __decorate([
        AppGenField({
            schema: {
                type: 'string',
                description: "Date time display format. For example: \n- YYYY DDDD MMM, HH:mm:ss\n-HH:mm:ss",
                default: 'YYYY DDDD MMM, HH:mm:ss'
            }
        }),
        __metadata("design:type", String)
    ], TapVariableDateTimePickerComponent.prototype, "format", void 0);
    __decorate([
        AppGenField({
            schema: {
                type: 'string'
            }
        }),
        __metadata("design:type", String)
    ], TapVariableDateTimePickerComponent.prototype, "label", void 0);
    TapVariableDateTimePickerComponent = __decorate([
        AppGenComponent({
            constraints: {
                isArray: 'NO'
            }
        }),
        __metadata("design:paramtypes", [ChangeDetectorRef, CurrentDeviceService, ToastController])
    ], TapVariableDateTimePickerComponent);
    return TapVariableDateTimePickerComponent;
}());
export { TapVariableDateTimePickerComponent };
if (false) {
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.pendingCallManager;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.pendingSubmitValue;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.error;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.loaded;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.format;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.label;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.formatDataWrite;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.formatDataRead;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype._variable;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.dateTimeValue;
    /**
     * @type {?}
     * @private
     */
    TapVariableDateTimePickerComponent.prototype.changeDetectorRef;
    /** @type {?} */
    TapVariableDateTimePickerComponent.prototype.toastController;
}
//# sourceMappingURL=data:application/json;base64, 