import { __decorate, __metadata } from "tslib";
import { Injector, Input } from '@angular/core';
import { CodeExecutor, DynamicOutput, PureRelationsComponent } from '@anglr/dynamic/relations';
import { RelationsEditorMetadata } from '@anglr/dynamic/relations-editor';
import { nameof } from '@jscrpt/common';
import { TransformDataRelationsMetadataLoader } from './transformData.metadata';
/**
 * Transform data relations component
 */
let TransformDataRelations = class TransformDataRelations {
    //######################### public properties - implementation of RelationsComponent #########################
    /**
     * @inheritdoc
     */
    get relationsOptions() {
        return this.ɵRelationsOptions;
    }
    set relationsOptions(value) {
        this.ɵRelationsOptions = value;
    }
    //######################### constructor #########################
    constructor(injector) {
        this.injector = injector;
        /**
         * Code executor used for execution o
         */
        this.codeExecutor = this.injector.get(CodeExecutor);
    }
    //######################### public methods - implementation of OnChanges #########################
    /**
     * Called when input value changes
     */
    async ngOnChanges(changes) {
        if (nameof('data') in changes) {
            if (!this.relationsOptions) {
                return;
            }
            const transformer = await this.codeExecutor.loadData(this.relationsOptions.id, this.relationsOptions.code);
            if (!transformer) {
                return;
            }
            try {
                this.transformedData = transformer(this.data);
            }
            catch (e) {
                console.error(e);
            }
        }
    }
    //######################### public properties - dynamic outputs #########################
    /**
     * @inheritdoc
     */
    invalidateVisuals() {
    }
};
__decorate([
    Input(),
    __metadata("design:type", Object)
], TransformDataRelations.prototype, "data", void 0);
__decorate([
    DynamicOutput(),
    __metadata("design:type", Object)
], TransformDataRelations.prototype, "transformedData", void 0);
TransformDataRelations = __decorate([
    PureRelationsComponent(),
    RelationsEditorMetadata(TransformDataRelationsMetadataLoader),
    __metadata("design:paramtypes", [Injector])
], TransformDataRelations);
export { TransformDataRelations };
//# sourceMappingURL=transformData.relations.js.map