import { __decorate, __metadata } from "tslib";
import { Injector } from '@angular/core';
import { defineAssignedProp, defineSkipInitProp, PureRelationsComponent, RelationsChangeDetector, RelationsComponentManager } from '@anglr/dynamic/relations';
import { RelationsEditorMetadata } from '@anglr/dynamic/relations-editor';
import { nameof } from '@jscrpt/common';
import { NEVER } from 'rxjs';
import { TriggerRelationsMetadataLoader } from './trigger.metadata';
/**
 * Trigger relations component
 */
let TriggerRelations = class TriggerRelations {
    //######################### public properties - implementation of RelationsComponent #########################
    /**
     * @inheritdoc
     */
    get relationsOptions() {
        return this.ɵRelationsOptions;
    }
    set relationsOptions(value) {
        this.ɵRelationsOptions = value;
        this.initialize();
    }
    //######################### constructor #########################
    constructor(injector) {
        //######################### public properties - inputs #########################
        /**
         * Trigger object
         */
        this.trigger = {};
        this.relationsChangeDetector = injector.get(RelationsChangeDetector);
        this.relationsComponentManager = injector.get(RelationsComponentManager);
    }
    //######################### public methods - implementation of RelationsComponent #########################
    /**
     * @inheritdoc
     */
    ngOnChanges(changes) {
        if (nameof('trigger') in changes) {
            if (this.relationsOptions?.endpoints?.length) {
                const id = this.relationsComponentManager.getId(this);
                if (id) {
                    for (const property of this.relationsOptions.endpoints) {
                        this.relationsChangeDetector.markForCheck({
                            componentId: id,
                            outputName: property.name,
                        });
                    }
                }
            }
        }
    }
    /**
     * @inheritdoc
     */
    invalidateVisuals() {
    }
    //######################### protected methods #########################
    /**
     * Initialize rest relations
     */
    initialize() {
        if (this.relationsOptions?.endpoints?.length) {
            for (const property of this.relationsOptions.endpoints) {
                Object.defineProperty(this, property.name, {
                    get: function () {
                        return this[`ɵ${property.name}`];
                    },
                    set: function (value) {
                        this[`ɵ${property.name}`] = value;
                        defineAssignedProp(this, property.name);
                    }
                });
                Object.defineProperty(this, `${property.name}Change`, {
                    value: NEVER,
                });
                if (property.skipInit) {
                    defineSkipInitProp(this, property.name);
                }
            }
        }
    }
};
TriggerRelations = __decorate([
    PureRelationsComponent(),
    RelationsEditorMetadata(TriggerRelationsMetadataLoader),
    __metadata("design:paramtypes", [Injector])
], TriggerRelations);
export { TriggerRelations };
//# sourceMappingURL=trigger.relations.js.map