import { __decorate, __metadata } from "tslib";
import { Injector, NgZone } from '@angular/core';
import { DebugData, PureRelationsComponent, RelationsChangeDetector } from '@anglr/dynamic/relations';
import { RelationsEditorMetadata } from '@anglr/dynamic/relations-editor';
import { isPresent, nameof } from '@jscrpt/common';
import { NEVER } from 'rxjs';
import { DebounceValueRelationsMetadataLoader } from './debounceValue.metadata';
/**
 * Debounce value relations component
 */
let DebounceValueRelations = class DebounceValueRelations {
    //######################### constructor #########################
    constructor(injector) {
        //######################### protected properties #########################
        /**
         * Subject used for emitting change in value
         */
        this.valueChange = NEVER;
        /**
         * Indication that initial value was already assigned
         */
        this.valueAssigned = false;
        /**
         * Reference number to timeout instance
         */
        this.timeout = null;
        this.ngZone = injector.get(NgZone);
        this.relationsChangeDetector = injector.get(RelationsChangeDetector);
    }
    //######################### public methods - implementation of RelationsComponent #########################
    /**
     * @inheritdoc
     */
    ngOnChanges(changes) {
        if (nameof('value') in changes) {
            if (isPresent(this.timeout)) {
                clearTimeout(this.timeout);
                this.timeout = null;
            }
            this.ngZone.runOutsideAngular(() => {
                var _a, _b;
                this.timeout = setTimeout(() => {
                    this.valueAssigned = true;
                    this.relationsChangeDetector.markForCheck({
                        componentId: this,
                        outputName: nameof('value'),
                    });
                }, (_b = (_a = this.relationsOptions) === null || _a === void 0 ? void 0 : _a.delay) !== null && _b !== void 0 ? _b : 0);
            });
        }
    }
    /**
     * @inheritdoc
     */
    invalidateVisuals() {
    }
};
DebounceValueRelations = __decorate([
    DebugData({
        inputs: [
            nameof('value'),
        ],
    }),
    PureRelationsComponent(),
    RelationsEditorMetadata(DebounceValueRelationsMetadataLoader),
    __metadata("design:paramtypes", [Injector])
], DebounceValueRelations);
export { DebounceValueRelations };
//# sourceMappingURL=debounceValue.relations.js.map