import { __decorate, __metadata } from "tslib";
import { DynamicOutput, PureRelationsComponent } from '@anglr/dynamic/relations';
import { RelationsEditorMetadata } from '@anglr/dynamic/relations-editor';
import { nameof } from '@jscrpt/common';
import Handlebars from 'handlebars';
import { DataTemplateRelationsMetadataLoader } from './dataTemplate.metadata';
/**
 * Data template relations component
 */
let DataTemplateRelations = class DataTemplateRelations {
    //######################### public properties - implementation of RelationsComponent #########################
    /**
     * @inheritdoc
     */
    get relationsOptions() {
        return this.ɵRelationsOptions;
    }
    set relationsOptions(value) {
        var _a, _b, _c, _d;
        this.ɵRelationsOptions = value;
        if ((_a = this.ɵRelationsOptions) === null || _a === void 0 ? void 0 : _a.template) {
            this.template = (_b = this.ɵRelationsOptions) === null || _b === void 0 ? void 0 : _b.template;
            this.compiledTemplate = Handlebars.compile((_c = this.template) !== null && _c !== void 0 ? _c : '');
            this.output = (_d = this.compiledTemplate(this.data)) !== null && _d !== void 0 ? _d : '';
        }
    }
    //######################### public methods - implementation of RelationsComponent #########################
    /**
     * @inheritdoc
     */
    ngOnChanges(changes) {
        var _a, _b, _c;
        if (nameof('template') in changes) {
            this.compiledTemplate = Handlebars.compile((_a = this.template) !== null && _a !== void 0 ? _a : '');
            this.output = this.compiledTemplate(this.data);
        }
        if (nameof('data') in changes) {
            this.output = (_c = (_b = this.compiledTemplate) === null || _b === void 0 ? void 0 : _b.call(this, this.data)) !== null && _c !== void 0 ? _c : '';
        }
    }
    /**
     * @inheritdoc
     */
    invalidateVisuals() {
    }
};
__decorate([
    DynamicOutput(),
    __metadata("design:type", Object)
], DataTemplateRelations.prototype, "output", void 0);
DataTemplateRelations = __decorate([
    PureRelationsComponent(),
    RelationsEditorMetadata(DataTemplateRelationsMetadataLoader)
], DataTemplateRelations);
export { DataTemplateRelations };
//# sourceMappingURL=dataTemplate.relations.js.map