var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
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);
};
import { Component, ComponentFactoryResolver, Injector, Input, ViewChild, ViewContainerRef } from '@angular/core';
import { PaletteService } from '../palette.service';
import { AbstractFieldReadComponent } from './abstract-field-read.component';
import { CaseField } from '../../../domain/definition/case-field.model';
import { FormGroup } from '@angular/forms';
import { plainToClassFromExist } from 'class-transformer';
var FieldReadComponent = /** @class */ (function (_super) {
    __extends(FieldReadComponent, _super);
    function FieldReadComponent(resolver, paletteService) {
        var _this = _super.call(this) || this;
        _this.resolver = resolver;
        _this.paletteService = paletteService;
        _this.withLabel = false;
        _this.caseFields = [];
        return _this;
    }
    FieldReadComponent.prototype.ngOnInit = function () {
        var _this = this;
        // Ensure all field values are resolved by label interpolation before the component is fully initialised.
        Promise.resolve(null).then(function () {
            var componentClass = _this.paletteService.getFieldComponentClass(_this.caseField, false);
            var injector = Injector.create([], _this.fieldContainer.parentInjector);
            var component = _this.resolver.resolveComponentFactory(componentClass).create(injector);
            // Provide component @Inputs
            component.instance['caseField'] = plainToClassFromExist(new CaseField(), _this.caseField);
            component.instance['caseFields'] = _this.caseFields;
            component.instance['formGroup'] = _this.formGroup;
            component.instance['caseReference'] = _this.caseReference;
            component.instance['context'] = _this.context;
            component.instance['registerControl'] = _this.registerControl || _this.defaultControlRegister();
            _this.fieldContainer.insert(component.hostView);
        });
    };
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], FieldReadComponent.prototype, "withLabel", void 0);
    __decorate([
        Input(),
        __metadata("design:type", FormGroup)
    ], FieldReadComponent.prototype, "formGroup", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Array)
    ], FieldReadComponent.prototype, "caseFields", void 0);
    __decorate([
        ViewChild('fieldContainer', { static: true, read: ViewContainerRef }),
        __metadata("design:type", ViewContainerRef)
    ], FieldReadComponent.prototype, "fieldContainer", void 0);
    FieldReadComponent = __decorate([
        Component({
            selector: 'ccd-field-read',
            template: "\n    <ccd-field-read-label [caseField]=\"caseField\" [withLabel]=\"withLabel\">\n      <ng-container #fieldContainer></ng-container>\n    </ccd-field-read-label>\n  "
        }),
        __metadata("design:paramtypes", [ComponentFactoryResolver, PaletteService])
    ], FieldReadComponent);
    return FieldReadComponent;
}(AbstractFieldReadComponent));
export { FieldReadComponent };
//# sourceMappingURL=field-read.component.js.map