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 { AbstractFieldWriteComponent } from './abstract-field-write.component';
import { CaseField } from '../../../domain/definition';
import { FormValidatorsService } from '../../../services/form';
import { plainToClassFromExist } from 'class-transformer';
var FieldWriteComponent = /** @class */ (function (_super) {
    __extends(FieldWriteComponent, _super);
    function FieldWriteComponent(resolver, paletteService, formValidatorsService) {
        var _this = _super.call(this) || this;
        _this.resolver = resolver;
        _this.paletteService = paletteService;
        _this.formValidatorsService = formValidatorsService;
        _this.caseFields = [];
        return _this;
    }
    FieldWriteComponent.prototype.addValidators = function (caseField, control) {
        this.formValidatorsService.addValidators(caseField, control);
    };
    FieldWriteComponent.prototype.ngOnInit = function () {
        var componentClass = this.paletteService.getFieldComponentClass(this.caseField, true);
        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['registerControl'] = this.registerControl || this.defaultControlRegister();
        component.instance['idPrefix'] = this.idPrefix;
        if (this.caseField.field_type.id === 'AddressGlobal') {
            component.instance['ignoreMandatory'] = true;
        }
        component.instance['isExpanded'] = this.isExpanded;
        this.fieldContainer.insert(component.hostView);
    };
    __decorate([
        Input(),
        __metadata("design:type", Array)
    ], FieldWriteComponent.prototype, "caseFields", void 0);
    __decorate([
        ViewChild('fieldContainer', { static: true, read: ViewContainerRef }),
        __metadata("design:type", ViewContainerRef)
    ], FieldWriteComponent.prototype, "fieldContainer", void 0);
    FieldWriteComponent = __decorate([
        Component({
            selector: 'ccd-field-write',
            template: "\n    <div [hidden]=\"caseField.hidden\">\n      <ng-container #fieldContainer></ng-container>\n    </div>\n  "
        }),
        __metadata("design:paramtypes", [ComponentFactoryResolver,
            PaletteService,
            FormValidatorsService])
    ], FieldWriteComponent);
    return FieldWriteComponent;
}(AbstractFieldWriteComponent));
export { FieldWriteComponent };
//# sourceMappingURL=field-write.component.js.map