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 { AbstractFieldWriteComponent } from '../base-field/abstract-field-write.component';
import { Component, Input } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { IsCompoundPipe } from '../utils/is-compound.pipe';
import { Constants } from '../../../commons/constants';
import { FormValidatorsService } from '../../../services/form/form-validators.service';
var WriteComplexFieldComponent = /** @class */ (function (_super) {
    __extends(WriteComplexFieldComponent, _super);
    function WriteComplexFieldComponent(isCompoundPipe, formValidatorsService) {
        var _this = _super.call(this) || this;
        _this.isCompoundPipe = isCompoundPipe;
        _this.formValidatorsService = formValidatorsService;
        _this.caseFields = [];
        _this.renderLabel = true;
        _this.ignoreMandatory = false;
        return _this;
    }
    WriteComplexFieldComponent.prototype.ngOnInit = function () {
        this.complexGroup = this.registerControl(new FormGroup({}));
    };
    WriteComplexFieldComponent.prototype.buildControlRegistrer = function (caseField) {
        var _this = this;
        return function (control) {
            if (_this.complexGroup.get(caseField.id)) {
                return _this.complexGroup.get(caseField.id);
            }
            // checks validators are required before calling formValidatorsService
            var validatorsRequired = function () {
                return 'AddressLine1' === caseField.id
                    && 'TextMax150' === caseField.field_type.id
                    && Constants.MANDATORY === caseField.display_context
                    || !this.ignoreMandatory;
            };
            if (validatorsRequired.call(_this)) {
                // console.log('WriteComplexFieldComponent add validators for caseField', caseField);
                _this.formValidatorsService.addValidators(caseField, control);
            }
            _this.complexGroup.addControl(caseField.id, control);
            return control;
        };
    };
    WriteComplexFieldComponent.prototype.buildIdPrefix = function (field) {
        return this.isCompoundPipe.transform(field) ? "" + this.idPrefix + field.id + "_" : "" + this.idPrefix;
    };
    __decorate([
        Input(),
        __metadata("design:type", Array)
    ], WriteComplexFieldComponent.prototype, "caseFields", void 0);
    __decorate([
        Input(),
        __metadata("design:type", FormGroup)
    ], WriteComplexFieldComponent.prototype, "formGroup", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], WriteComplexFieldComponent.prototype, "renderLabel", void 0);
    __decorate([
        Input(),
        __metadata("design:type", Object)
    ], WriteComplexFieldComponent.prototype, "ignoreMandatory", void 0);
    WriteComplexFieldComponent = __decorate([
        Component({
            selector: 'ccd-write-complex-type-field',
            template: "\n    <div class=\"form-group\" [id]=\"id()\">\n\n      <h2 *ngIf=\"renderLabel\" class=\"heading-h2\">{{caseField | ccdFieldLabel}}</h2>\n      <ng-container *ngFor=\"let field of caseField | ccdFieldsFilter:true\">\n        <ng-container [ngSwitch]=\"field | ccdIsReadOnly\">\n          <ccd-field-read *ngSwitchCase=\"true\"\n                          ccdConditionalShow\n                          ccdLabelSubstitutor\n                          [caseField]=\"field\"\n                          [contextFields]=\"caseFields\"\n                          [caseFields]=\"caseFields\"\n                          [formGroup]=\"formGroup\"\n                          [withLabel]=\"true\"\n                          [idPrefix]=\"buildIdPrefix(field)\"\n                          [registerControl]=\"buildControlRegistrer(field)\">\n          </ccd-field-read>\n          <ccd-field-write *ngSwitchCase=\"false\"\n                           ccdConditionalShow\n                           ccdLabelSubstitutor\n                           [greyBarEnabled]=\"true\"\n                           [caseField]=\"field\"\n                           [contextFields]=\"caseFields\"\n                           [caseFields]=\"caseFields\"\n                           [formGroup]=\"formGroup\"\n                           [complexFormGroup]=\"complexGroup\"\n                           [registerControl]=\"buildControlRegistrer(field)\"\n                           [idPrefix]=\"buildIdPrefix(field)\">\n          </ccd-field-write>\n        </ng-container>\n      </ng-container>\n    </div>\n  ",
            styles: ["\n    .complex-panel{margin:13px 0px;border:1px solid #bfc1c3}.complex-panel .complex-panel-title{background-color:#dee0e2;padding:5px;border-bottom:1px solid #bfc1c3;font-weight:bold;display:block;color:#0b0c0c;padding-bottom:2px;font-family:\"nta\",Arial,sans-serif;font-weight:700;text-transform:none;font-size:16px;line-height:1.25}@media (min-width: 641px){.complex-panel .complex-panel-title{font-size:19px;line-height:1.31579}}.complex-panel .complex-panel-table>tbody>tr>th{vertical-align:top}.complex-panel .complex-panel-table>tbody>tr:last-child>th,.complex-panel .complex-panel-table>tbody>tr:last-child>td{border-bottom:none}.complex-panel .complex-panel-simple-field th{padding-left:5px;width:295px}.complex-panel .complex-panel-compound-field td{padding:5px}\n  "]
        }),
        __metadata("design:paramtypes", [IsCompoundPipe, FormValidatorsService])
    ], WriteComplexFieldComponent);
    return WriteComplexFieldComponent;
}(AbstractFieldWriteComponent));
export { WriteComplexFieldComponent };
//# sourceMappingURL=write-complex-field.component.js.map