import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { AbstractFieldWriteComponent } from '../base-field/abstract-field-write.component';
import * as i0 from "@angular/core";
import * as i1 from "@angular/common";
import * as i2 from "@angular/forms";
import * as i3 from "../utils/field-label.pipe";
import * as i4 from "../utils/first-error.pipe";
import * as i5 from "rpx-xui-translation";
const _c0 = a0 => ({ "form-group-error": a0 });
const _c1 = a0 => ({ selected: a0 });
function WriteDynamicRadioListFieldComponent_span_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 7);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "ccdFieldLabel");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 1, ctx_r0.caseField));
} }
function WriteDynamicRadioListFieldComponent_span_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 8);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "rpxTranslate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 1, ctx_r0.caseField.hint_text));
} }
function WriteDynamicRadioListFieldComponent_span_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 7);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "rpxTranslate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 1, "Select an option below"));
} }
function WriteDynamicRadioListFieldComponent_span_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 9);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "ccdFirstError");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 1, ctx_r0.dynamicRadioListControl.errors));
} }
function WriteDynamicRadioListFieldComponent_div_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 10);
    i0.ɵɵelement(1, "input", 11);
    i0.ɵɵelementStart(2, "label", 12);
    i0.ɵɵtext(3);
    i0.ɵɵpipe(4, "rpxTranslate");
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const radioButton_r2 = ctx.$implicit;
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(9, _c1, ctx_r0.dynamicRadioListControl.value === radioButton_r2.code));
    i0.ɵɵadvance();
    i0.ɵɵproperty("id", ctx_r0.createElementId(radioButton_r2.code))("name", ctx_r0.id())("formControl", ctx_r0.dynamicRadioListControl)("value", radioButton_r2.code);
    i0.ɵɵadvance();
    i0.ɵɵproperty("for", ctx_r0.createElementId(radioButton_r2.code));
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(4, 7, radioButton_r2.label));
} }
export class WriteDynamicRadioListFieldComponent extends AbstractFieldWriteComponent {
    dynamicRadioListControl;
    ngOnInit() {
        /**
         * Reassigning list_items from formatted_list when list_items is empty
         */
        if (!this.caseField.list_items && this.caseField.formatted_value && this.caseField.formatted_value.list_items) {
            this.caseField.list_items = this.caseField.formatted_value.list_items;
        }
        if (!this.caseField.value && this.caseField.formatted_value?.value) {
            this.caseField.value = this.caseField.formatted_value.value?.code;
        }
        const isNull = this.caseField.value === undefined || this.caseField.value === '';
        if (isNull || typeof this.caseField.value === 'object') {
            this.caseField.value = [];
        }
        this.dynamicRadioListControl = this.registerControl(new FormControl(this.caseField.value));
        this.dynamicRadioListControl.setValue(this.caseField.value);
    }
    createElementId(name) {
        // EXUI-2462 - parent may not always have value with content
        // this is independent from the caseField.list_items so is irrelevant to event journey
        return this.parent?.value?.id ? this.parent.value.id + this.parent.value.value : super.createElementId(name);
    }
    static ɵfac = /*@__PURE__*/ (() => { let ɵWriteDynamicRadioListFieldComponent_BaseFactory; return function WriteDynamicRadioListFieldComponent_Factory(__ngFactoryType__) { return (ɵWriteDynamicRadioListFieldComponent_BaseFactory || (ɵWriteDynamicRadioListFieldComponent_BaseFactory = i0.ɵɵgetInheritedFactory(WriteDynamicRadioListFieldComponent)))(__ngFactoryType__ || WriteDynamicRadioListFieldComponent); }; })();
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: WriteDynamicRadioListFieldComponent, selectors: [["ccd-write-dynamic-radio-list-field"]], features: [i0.ɵɵInheritDefinitionFeature], decls: 10, vars: 10, consts: [[1, "form-group", "bottom-30", 3, "ngClass", "id"], [2, "display", "none"], [3, "for"], ["class", "form-label", 4, "ngIf"], ["class", "form-hint", 4, "ngIf"], ["class", "error-message", 4, "ngIf"], ["class", "multiple-choice", 3, "ngClass", 4, "ngFor", "ngForOf"], [1, "form-label"], [1, "form-hint"], [1, "error-message"], [1, "multiple-choice", 3, "ngClass"], ["type", "radio", 1, "form-control", 3, "id", "name", "formControl", "value"], [1, "form-label", 3, "for"]], template: function WriteDynamicRadioListFieldComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "fieldset");
            i0.ɵɵelement(2, "legend", 1);
            i0.ɵɵelementStart(3, "label", 2);
            i0.ɵɵtemplate(4, WriteDynamicRadioListFieldComponent_span_4_Template, 3, 3, "span", 3)(5, WriteDynamicRadioListFieldComponent_span_5_Template, 3, 3, "span", 4)(6, WriteDynamicRadioListFieldComponent_span_6_Template, 3, 3, "span", 3)(7, WriteDynamicRadioListFieldComponent_span_7_Template, 3, 3, "span", 5);
            i0.ɵɵelementEnd();
            i0.ɵɵelementContainerStart(8);
            i0.ɵɵtemplate(9, WriteDynamicRadioListFieldComponent_div_9_Template, 5, 11, "div", 6);
            i0.ɵɵelementContainerEnd();
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(8, _c0, !ctx.dynamicRadioListControl.valid && ctx.dynamicRadioListControl.dirty))("id", ctx.id());
            i0.ɵɵadvance(3);
            i0.ɵɵproperty("for", ctx.id());
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", ctx.caseField.label);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", ctx.caseField.hint_text);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", !ctx.caseField.label && !ctx.caseField.hint_text);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", ctx.dynamicRadioListControl.errors && ctx.dynamicRadioListControl.dirty);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngForOf", ctx.caseField.list_items);
        } }, dependencies: [i1.NgClass, i1.NgForOf, i1.NgIf, i2.DefaultValueAccessor, i2.RadioControlValueAccessor, i2.NgControlStatus, i2.FormControlDirective, i3.FieldLabelPipe, i4.FirstErrorPipe, i5.RpxTranslatePipe], encapsulation: 2 });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(WriteDynamicRadioListFieldComponent, [{
        type: Component,
        args: [{ selector: 'ccd-write-dynamic-radio-list-field', template: "<div class=\"form-group bottom-30\"\n    [ngClass]=\"{'form-group-error': !dynamicRadioListControl.valid && dynamicRadioListControl.dirty}\" [id]=\"id()\">\n  <fieldset>\n    <legend style=\"display: none;\"></legend>\n    <label [for]=\"id()\">\n        <span class=\"form-label\" *ngIf=\"caseField.label\">{{(caseField | ccdFieldLabel)}}</span>\n        <span class=\"form-hint\" *ngIf=\"caseField.hint_text\">{{caseField.hint_text | rpxTranslate}}</span>\n        <span class=\"form-label\" *ngIf=\"!caseField.label && !caseField.hint_text\">{{'Select an option below' | rpxTranslate}}</span>\n        <span class=\"error-message\"\n            *ngIf=\"dynamicRadioListControl.errors && dynamicRadioListControl.dirty\">{{(dynamicRadioListControl.errors |\n            ccdFirstError)}}</span>\n    </label>\n\n    <ng-container>\n      <div class=\"multiple-choice\" *ngFor=\"let radioButton of caseField.list_items\" [ngClass]=\"{selected: dynamicRadioListControl.value === radioButton.code}\">\n        <input class=\"form-control\" [id]=\"createElementId(radioButton.code)\" [name]=\"id()\" type=\"radio\" [formControl]=\"dynamicRadioListControl\" [value]=\"radioButton.code\">\n        <label class=\"form-label\" [for]=\"createElementId(radioButton.code)\">{{radioButton.label | rpxTranslate}}</label>\n      </div>\n    </ng-container>\n  </fieldset>\n</div>\n" }]
    }], null, null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(WriteDynamicRadioListFieldComponent, { className: "WriteDynamicRadioListFieldComponent", filePath: "lib/shared/components/palette/dynamic-radio-list/write-dynamic-radio-list-field.component.ts", lineNumber: 9 }); })();
//# sourceMappingURL=data:application/json;base64, 