import { __decorate, __metadata } from "tslib";
import { Injector } from '@angular/core';
import { DynamicOutput, PureRelationsComponent } from '@anglr/dynamic/relations';
import { RelationsEditorMetadata } from '@anglr/dynamic/relations-editor';
import { MergeRelationsMetadataLoader } from './merge.metadata';
/**
 * Merge relations component
 */
let MergeRelations = class MergeRelations {
    //######################### public properties - implementation of RelationsComponent #########################
    /**
     * @inheritdoc
     */
    get relationsOptions() {
        return this.ɵRelationsOptions;
    }
    set relationsOptions(value) {
        this.ɵRelationsOptions = value;
        this.initialize();
    }
    //######################### constructor #########################
    constructor(injector) {
        this.injector = injector;
    }
    //######################### public properties - dynamic outputs #########################
    /**
     * @inheritdoc
     */
    invalidateVisuals() {
    }
    //######################### protected methods #########################
    /**
     * Initialize rest relations
     */
    initialize() {
        //TODO optimize property setter. Currently triggers multiple times when properties are set in sync.
        if (this.relationsOptions) {
            if (this.relationsOptions.properties?.length) {
                for (const name of this.relationsOptions.properties) {
                    if (name) {
                        Object.defineProperty(this, name, {
                            set: value => {
                                this.mergedObject ?? (this.mergedObject = {});
                                this.mergedObject[name] = value;
                                this.mergedObject = { ...this.mergedObject };
                            }
                        });
                    }
                }
            }
        }
    }
};
__decorate([
    DynamicOutput(),
    __metadata("design:type", Object)
], MergeRelations.prototype, "mergedObject", void 0);
MergeRelations = __decorate([
    PureRelationsComponent(),
    RelationsEditorMetadata(MergeRelationsMetadataLoader),
    __metadata("design:paramtypes", [Injector])
], MergeRelations);
export { MergeRelations };
//# sourceMappingURL=merge.relations.js.map