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;
};
import { Component } from '@angular/core';
import { AbstractFieldWriteComponent } from '../base-field/abstract-field-write.component';
import { FormControl, FormGroup, FormArray } from '@angular/forms';
var WriteOrderSummaryFieldComponent = /** @class */ (function (_super) {
    __extends(WriteOrderSummaryFieldComponent, _super);
    function WriteOrderSummaryFieldComponent() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    /*
      These are implemented manually rather than using WriteComplexFieldComponent. The reason
      is because the view is readonly the tree of form controls is not being built automatically
      and has to be built manually.
    */
    WriteOrderSummaryFieldComponent.prototype.ngOnInit = function () {
        var _this = this;
        var orderSummaryGroup = this.registerControl(new FormGroup({}));
        var paymentReference = new FormControl(this.caseField.value.PaymentReference);
        orderSummaryGroup.addControl('PaymentReference', paymentReference);
        var paymentTotal = new FormControl(this.caseField.value.PaymentTotal);
        orderSummaryGroup.addControl('PaymentTotal', paymentTotal);
        var feesArray = new FormArray([]);
        this.caseField.value.Fees.forEach(function (fee) {
            feesArray.push(_this.getFeeValue(fee.value));
        });
        orderSummaryGroup.addControl('Fees', feesArray);
    };
    WriteOrderSummaryFieldComponent.prototype.getFeeValue = function (feeValue) {
        var feeGroup = new FormGroup({});
        feeGroup.addControl('FeeCode', new FormControl(feeValue.FeeCode));
        feeGroup.addControl('FeeAmount', new FormControl(feeValue.FeeAmount));
        feeGroup.addControl('FeeDescription', new FormControl(feeValue.FeeDescription));
        feeGroup.addControl('FeeVersion', new FormControl(feeValue.FeeVersion));
        var feeValueGroup = new FormGroup({});
        feeValueGroup.addControl('value', feeGroup);
        return feeValueGroup;
    };
    WriteOrderSummaryFieldComponent = __decorate([
        Component({
            selector: 'ccd-write-order-summary-field',
            template: "\n    <ccd-read-order-summary-field [caseField]=\"caseField\"></ccd-read-order-summary-field>\n  "
        })
    ], WriteOrderSummaryFieldComponent);
    return WriteOrderSummaryFieldComponent;
}(AbstractFieldWriteComponent));
export { WriteOrderSummaryFieldComponent };
//# sourceMappingURL=write-order-summary-field.component.js.map