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 WriteFixedListFieldComponent_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 WriteFixedListFieldComponent_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 WriteFixedListFieldComponent_span_4_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.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind2(2, 1, ctx_r0.fixedListFormControl.errors, ctx_r0.caseField.label), " ");
} }
function WriteFixedListFieldComponent_option_8_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 WriteFixedListFieldComponent extends AbstractFieldWriteComponent {
    fixedListFormControl;
    get listItems() {
        if (this.caseField) {
            if (this.caseField.list_items) {
                return this.caseField.list_items;
            }
            if (this.caseField.formatted_value && this.caseField.formatted_value.list_items) {
                return this.caseField.formatted_value.list_items;
            }
        }
        return [];
    }
    ngOnInit() {
        const isNull = this.caseField.value === undefined || this.caseField.value === '';
        if (isNull) {
            this.caseField.value = null;
        }
        this.fixedListFormControl = this.registerControl(new FormControl(this.caseField.value));
        this.fixedListFormControl.setValue(this.caseField.value);
    }
    static ɵfac = /*@__PURE__*/ (() => { let ɵWriteFixedListFieldComponent_BaseFactory; return function WriteFixedListFieldComponent_Factory(__ngFactoryType__) { return (ɵWriteFixedListFieldComponent_BaseFactory || (ɵWriteFixedListFieldComponent_BaseFactory = i0.ɵɵgetInheritedFactory(WriteFixedListFieldComponent)))(__ngFactoryType__ || WriteFixedListFieldComponent); }; })();
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: WriteFixedListFieldComponent, selectors: [["ccd-write-fixed-list-field"]], features: [i0.ɵɵInheritDefinitionFeature], decls: 9, vars: 11, 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 WriteFixedListFieldComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "label", 1);
            i0.ɵɵtemplate(2, WriteFixedListFieldComponent_span_2_Template, 3, 3, "span", 2);
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(3, WriteFixedListFieldComponent_span_3_Template, 3, 3, "span", 3)(4, WriteFixedListFieldComponent_span_4_Template, 3, 4, "span", 4);
            i0.ɵɵelementStart(5, "select", 5)(6, "option", 6);
            i0.ɵɵtext(7, "--Select a value--");
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(8, WriteFixedListFieldComponent_option_8_Template, 3, 4, "option", 7);
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(9, _c0, !ctx.fixedListFormControl.valid && (ctx.fixedListFormControl.dirty || ctx.fixedListFormControl.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.fixedListFormControl.errors && (ctx.fixedListFormControl.dirty || ctx.fixedListFormControl.touched));
            i0.ɵɵadvance();
            i0.ɵɵproperty("id", ctx.id())("formControl", ctx.fixedListFormControl);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngValue", null);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngForOf", ctx.listItems);
        } }, 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(WriteFixedListFieldComponent, [{
        type: Component,
        args: [{ selector: 'ccd-write-fixed-list-field', template: "<div class=\"form-group\" [ngClass]=\"{'form-group-error': !fixedListFormControl.valid && (fixedListFormControl.dirty || fixedListFormControl.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=\"error-message\" *ngIf=\"fixedListFormControl.errors && (fixedListFormControl.dirty || fixedListFormControl.touched)\">\n    {{(fixedListFormControl.errors | ccdFirstError:caseField.label)}}\n  </span>\n\n  <select class=\"form-control ccd-dropdown bottom-30\" [id]=\"id()\" [formControl]=\"fixedListFormControl\">\n    <option [ngValue]=null>--Select a value--</option>\n    <option [ngValue]=\"type.code\" *ngFor=\"let type of listItems\">{{type.label | rpxTranslate}}</option>\n  </select>\n\n</div>\n" }]
    }], null, null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(WriteFixedListFieldComponent, { className: "WriteFixedListFieldComponent", filePath: "lib/shared/components/palette/fixed-list/write-fixed-list-field.component.ts", lineNumber: 9 }); })();
//# sourceMappingURL=data:application/json;base64, 