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 });
function WriteDynamicListFieldComponent_span_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 8);
    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 WriteDynamicListFieldComponent_span_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 9);
    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 WriteDynamicListFieldComponent_span_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 8);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "rpxTranslate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 1, "Select an option from the dropdown"));
} }
function WriteDynamicListFieldComponent_span_5_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 10);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "ccdFirstError");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind2(2, 1, ctx_r0.dynamicListFormControl.errors, ctx_r0.caseField.label));
} }
function WriteDynamicListFieldComponent_option_10_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "option", 6);
    i0.ɵɵtext(1);
    i0.ɵɵpipe(2, "rpxTranslate");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const type_r2 = ctx.$implicit;
    i0.ɵɵproperty("ngValue", type_r2.code);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 2, type_r2.label));
} }
export class WriteDynamicListFieldComponent extends AbstractFieldWriteComponent {
    dynamicListFormControl;
    ngOnInit() {
        /**
         * Reassigning list_items from formatted_value 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;
        }
        /**
         * Reassigning value from formatted_value when value is empty
         */
        if (!this.caseField.value) {
            if (this.caseField.formatted_value && this.caseField.formatted_value.value && this.caseField.formatted_value.value.code) {
                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 = null;
        }
        this.dynamicListFormControl = this.registerControl(new FormControl(this.caseField.value));
        this.dynamicListFormControl.setValue(this.caseField.value);
    }
    static ɵfac = /*@__PURE__*/ (() => { let ɵWriteDynamicListFieldComponent_BaseFactory; return function WriteDynamicListFieldComponent_Factory(__ngFactoryType__) { return (ɵWriteDynamicListFieldComponent_BaseFactory || (ɵWriteDynamicListFieldComponent_BaseFactory = i0.ɵɵgetInheritedFactory(WriteDynamicListFieldComponent)))(__ngFactoryType__ || WriteDynamicListFieldComponent); }; })();
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: WriteDynamicListFieldComponent, selectors: [["ccd-write-dynamic-list-field"]], features: [i0.ɵɵInheritDefinitionFeature], decls: 11, vars: 15, consts: [[1, "form-group", 3, "ngClass"], [3, "for"], ["class", "form-label", 4, "ngIf"], ["class", "form-hint", 4, "ngIf"], ["class", "error-message", 4, "ngIf"], [1, "form-control", "ccd-dropdown", "bottom-30", 3, "id", "formControl"], [3, "ngValue"], [3, "ngValue", 4, "ngFor", "ngForOf"], [1, "form-label"], [1, "form-hint"], [1, "error-message"]], template: function WriteDynamicListFieldComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "label", 1);
            i0.ɵɵtemplate(2, WriteDynamicListFieldComponent_span_2_Template, 3, 3, "span", 2);
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(3, WriteDynamicListFieldComponent_span_3_Template, 3, 3, "span", 3)(4, WriteDynamicListFieldComponent_span_4_Template, 3, 3, "span", 2)(5, WriteDynamicListFieldComponent_span_5_Template, 3, 4, "span", 4);
            i0.ɵɵelementStart(6, "select", 5)(7, "option", 6);
            i0.ɵɵtext(8);
            i0.ɵɵpipe(9, "rpxTranslate");
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(10, WriteDynamicListFieldComponent_option_10_Template, 3, 4, "option", 7);
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(13, _c0, !ctx.dynamicListFormControl.valid && (ctx.dynamicListFormControl.dirty || ctx.dynamicListFormControl.touched)));
            i0.ɵɵadvance();
            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.dynamicListFormControl.errors && ctx.dynamicListFormControl.dirty);
            i0.ɵɵadvance();
            i0.ɵɵproperty("id", ctx.id())("formControl", ctx.dynamicListFormControl);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngValue", null);
            i0.ɵɵadvance();
            i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(9, 11, "--Select a value--"));
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngForOf", ctx.caseField.list_items);
        } }, dependencies: [i1.NgClass, i1.NgForOf, i1.NgIf, i2.NgSelectOption, i2.ɵNgSelectMultipleOption, i2.SelectControlValueAccessor, i2.NgControlStatus, i2.FormControlDirective, i3.FieldLabelPipe, i4.FirstErrorPipe, i5.RpxTranslatePipe], encapsulation: 2 });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(WriteDynamicListFieldComponent, [{
        type: Component,
        args: [{ selector: 'ccd-write-dynamic-list-field', template: "<div class=\"form-group\"\n  [ngClass]=\"{'form-group-error': !dynamicListFormControl.valid && (dynamicListFormControl.dirty || dynamicListFormControl.touched)}\">\n\n  <label [for]=\"id()\">\n    <span class=\"form-label\" *ngIf=\"caseField.label\">{{(caseField | ccdFieldLabel)}}</span>\n  </label>\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 from the dropdown' | rpxTranslate}}</span>\n  <span class=\"error-message\"\n    *ngIf=\"dynamicListFormControl.errors && dynamicListFormControl.dirty\">{{(dynamicListFormControl.errors |\n    ccdFirstError:caseField.label)}}</span>\n\n  <select class=\"form-control ccd-dropdown bottom-30\" [id]=\"id()\"\n    [formControl]=\"dynamicListFormControl\">\n    <option [ngValue]=null>{{'--Select a value--' | rpxTranslate}}</option>\n    <option [ngValue]=\"type.code\" *ngFor=\"let type of caseField.list_items\">{{type.label | rpxTranslate}}</option>\n  </select>\n</div>\n" }]
    }], null, null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(WriteDynamicListFieldComponent, { className: "WriteDynamicListFieldComponent", filePath: "lib/shared/components/palette/dynamic-list/write-dynamic-list-field.component.ts", lineNumber: 9 }); })();
//# sourceMappingURL=data:application/json;base64, 