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 => ({ "govuk-input--error": a0 });
function WriteTextFieldComponent_label_1_span_1_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(2);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(2, 1, ctx_r0.caseField));
} }
function WriteTextFieldComponent_label_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "label", 5);
    i0.ɵɵtemplate(1, WriteTextFieldComponent_label_1_span_1_Template, 3, 3, "span", 6);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵproperty("for", ctx_r0.id());
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", ctx_r0.caseField.label);
} }
function WriteTextFieldComponent_span_2_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 WriteTextFieldComponent_span_3_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.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind2(2, 1, ctx_r0.textControl.errors, ctx_r0.caseField.label), " ");
} }
export class WriteTextFieldComponent extends AbstractFieldWriteComponent {
    textControl;
    ngOnInit() {
        this.textControl = this.registerControl(new FormControl(this.caseField.value));
    }
    onBlur($event) {
        $event.target.value = $event.target.value.trim();
    }
    static ɵfac = /*@__PURE__*/ (() => { let ɵWriteTextFieldComponent_BaseFactory; return function WriteTextFieldComponent_Factory(__ngFactoryType__) { return (ɵWriteTextFieldComponent_BaseFactory || (ɵWriteTextFieldComponent_BaseFactory = i0.ɵɵgetInheritedFactory(WriteTextFieldComponent)))(__ngFactoryType__ || WriteTextFieldComponent); }; })();
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: WriteTextFieldComponent, selectors: [["ccd-write-text-field"]], features: [i0.ɵɵInheritDefinitionFeature], decls: 5, vars: 12, consts: [[1, "form-group", 3, "ngClass"], [3, "for", 4, "ngIf"], ["class", "form-hint", 4, "ngIf"], ["class", "error-message", 4, "ngIf"], [1, "form-control", "bottom-30", 3, "blur", "ngClass", "id", "type", "formControl"], [3, "for"], ["class", "form-label", 4, "ngIf"], [1, "form-label"], [1, "form-hint"], [1, "error-message"]], template: function WriteTextFieldComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0);
            i0.ɵɵtemplate(1, WriteTextFieldComponent_label_1_Template, 2, 2, "label", 1)(2, WriteTextFieldComponent_span_2_Template, 3, 3, "span", 2)(3, WriteTextFieldComponent_span_3_Template, 3, 4, "span", 3);
            i0.ɵɵelementStart(4, "input", 4);
            i0.ɵɵlistener("blur", function WriteTextFieldComponent_Template_input_blur_4_listener($event) { return ctx.onBlur($event); });
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(8, _c0, !!ctx.textControl && !ctx.textControl.valid && (ctx.textControl.dirty || ctx.textControl.touched)));
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", !ctx.caseField.hidden);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", ctx.caseField.hint_text);
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngIf", (ctx.textControl == null ? null : ctx.textControl.errors) && (ctx.textControl.dirty || ctx.textControl.touched));
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(10, _c1, (ctx.textControl == null ? null : ctx.textControl.errors) && (ctx.textControl.dirty || ctx.textControl.touched)))("id", ctx.id())("type", ctx.caseField.hidden ? "hidden" : "text")("formControl", ctx.textControl);
        } }, dependencies: [i1.NgClass, i1.NgIf, i2.DefaultValueAccessor, i2.NgControlStatus, i2.FormControlDirective, i3.FieldLabelPipe, i4.FirstErrorPipe, i5.RpxTranslatePipe], encapsulation: 2 });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(WriteTextFieldComponent, [{
        type: Component,
        args: [{ selector: 'ccd-write-text-field', template: "<div class=\"form-group\" [ngClass]=\"{'form-group-error': !!textControl && !textControl.valid && (textControl.dirty || textControl.touched)}\">\n  <label [for]=\"id()\" *ngIf=\"!caseField.hidden\">\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=\"textControl?.errors && (textControl.dirty || textControl.touched)\">\n    {{textControl.errors | ccdFirstError:caseField.label}}\n  </span>\n  <input class=\"form-control bottom-30\" [ngClass]=\"{'govuk-input--error': textControl?.errors && (textControl.dirty || textControl.touched)}\"\n    [id]=\"id()\" [type]=\"caseField.hidden ? 'hidden' : 'text'\" [formControl]=\"textControl\" (blur)=\"onBlur($event)\">\n</div>\n" }]
    }], null, null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(WriteTextFieldComponent, { className: "WriteTextFieldComponent", filePath: "lib/shared/components/palette/text/write-text-field.component.ts", lineNumber: 9 }); })();
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoid3JpdGUtdGV4dC1maWVsZC5jb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9wcm9qZWN0cy9jY2QtY2FzZS11aS10b29sa2l0L3NyYy9saWIvc2hhcmVkL2NvbXBvbmVudHMvcGFsZXR0ZS90ZXh0L3dyaXRlLXRleHQtZmllbGQuY29tcG9uZW50LnRzIiwiLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vcHJvamVjdHMvY2NkLWNhc2UtdWktdG9vbGtpdC9zcmMvbGliL3NoYXJlZC9jb21wb25lbnRzL3BhbGV0dGUvdGV4dC93cml0ZS10ZXh0LWZpZWxkLmh0bWwiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFNBQVMsRUFBVSxNQUFNLGVBQWUsQ0FBQztBQUNsRCxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7QUFDN0MsT0FBTyxFQUFFLDJCQUEyQixFQUFFLE1BQU0sOENBQThDLENBQUM7Ozs7Ozs7Ozs7SUNBdkYsK0JBQWlEO0lBQUEsWUFBNkI7O0lBQUEsaUJBQU87OztJQUFwQyxjQUE2QjtJQUE3Qiw0REFBNkI7OztJQURoRixnQ0FBOEM7SUFDNUMsa0ZBQWlEO0lBQ25ELGlCQUFROzs7SUFGRCxpQ0FBWTtJQUNTLGNBQXFCO0lBQXJCLDZDQUFxQjs7O0lBRWpELCtCQUFvRDtJQUFBLFlBQXNDOztJQUFBLGlCQUFPOzs7SUFBN0MsY0FBc0M7SUFBdEMsc0VBQXNDOzs7SUFDMUYs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