"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManyToManyValueConverter = void 0;
var relation_helper_1 = require("../model/relation-helper");
var aurelia_binding_1 = require("aurelia-binding");
var aurelia_framework_1 = require("aurelia-framework");
var ManyToManyValueConverter = exports.ManyToManyValueConverter = (function () {
    function ManyToManyValueConverter(parser) {
        this.parser = parser;
    }
    ManyToManyValueConverter.prototype.toView = function (value, propertyExpression, createTagFnOrStr, propertyTarget) {
        if (isEmpty(value)) {
            console.warn('ManyToManyValueConverter: Cannot use ManyToMany value converter without an instance of an object');
            return;
        }
        if (isEmpty(propertyExpression)) {
            console.warn('ManyToManyValueConverter: You must specify a property expression parameter.');
            return;
        }
        var entity = value;
        var helperName = '__' + propertyExpression + 'Helper';
        if (Object.keys(value).indexOf(helperName) < 0) {
            value[helperName] = new relation_helper_1.ManyToManyRelationHelper(entity, propertyExpression, createTagFnOrStr, propertyTarget);
        }
        else if (value[helperName] instanceof relation_helper_1.ManyToManyRelationHelper) {
            value[helperName].initializeData(value[helperName]);
        }
        var getExp = this.parser.parse(helperName + '.selectedEntitiesId');
        return getExp.evaluate({ bindingContext: value, overrideContext: null });
    };
    ManyToManyValueConverter = __decorate([
        aurelia_framework_1.autoinject,
        (0, aurelia_binding_1.valueConverter)("manyToMany"),
        __metadata("design:paramtypes", [aurelia_binding_1.Parser])
    ], ManyToManyValueConverter);
    return ManyToManyValueConverter;
}());

//# sourceMappingURL=many-to-many-value-converter.js.map
