import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { BrowserService } from '../../../services/browser/browser.service';
import { AbstractFieldWriteComponent } from '../base-field/abstract-field-write.component';
import * as i0 from "@angular/core";
import * as i1 from "../../../services/browser/browser.service";
import * as i2 from "@angular/common";
import * as i3 from "@angular/forms";
import * as i4 from "../utils/field-label.pipe";
import * as i5 from "../utils/first-error.pipe";
import * as i6 from "rpx-xui-translation";
const _c0 = a0 => ({ "form-group-error": a0 });
const _c1 = a0 => ({ "govuk-textarea--error": a0 });
function WriteTextAreaFieldComponent_span_2_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 6);
    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 WriteTextAreaFieldComponent_span_3_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 7);
    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 WriteTextAreaFieldComponent_span_4_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span", 8);
    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.textareaControl.errors, ctx_r0.caseField.label), " ");
} }
export class WriteTextAreaFieldComponent extends AbstractFieldWriteComponent {
    browserService;
    textareaControl;
    constructor(browserService) {
        super();
        this.browserService = browserService;
    }
    ngOnInit() {
        this.textareaControl = this.registerControl(new FormControl(this.caseField.value));
    }
    autoGrow(event) {
        if (this.browserService.isIEOrEdge()) {
            event.target.style.height = 'auto';
            event.target.style.height = `${event.target.scrollHeight}px`;
            event.target.scrollTop = event.target.scrollHeight;
        }
    }
    static ɵfac = function WriteTextAreaFieldComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || WriteTextAreaFieldComponent)(i0.ɵɵdirectiveInject(i1.BrowserService)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: WriteTextAreaFieldComponent, selectors: [["ccd-write-text-area-field"]], features: [i0.ɵɵProvidersFeature([BrowserService]), i0.ɵɵInheritDefinitionFeature], decls: 6, vars: 12, consts: [[1, "form-group", 3, "ngClass"], [3, "for"], ["class", "form-label", 4, "ngIf"], ["class", "form-hint", 4, "ngIf"], ["class", "error-message", 4, "ngIf"], ["rows", "3", 1, "form-control", "bottom-30", 3, "input", "ngClass", "id", "formControl"], [1, "form-label"], [1, "form-hint"], [1, "error-message"]], template: function WriteTextAreaFieldComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "label", 1);
            i0.ɵɵtemplate(2, WriteTextAreaFieldComponent_span_2_Template, 3, 3, "span", 2);
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(3, WriteTextAreaFieldComponent_span_3_Template, 3, 3, "span", 3)(4, WriteTextAreaFieldComponent_span_4_Template, 3, 4, "span", 4);
            i0.ɵɵelementStart(5, "textarea", 5);
            i0.ɵɵlistener("input", function WriteTextAreaFieldComponent_Template_textarea_input_5_listener($event) { return ctx.autoGrow($event); });
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(8, _c0, !ctx.textareaControl.valid && ctx.textareaControl.dirty));
            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.textareaControl.errors && (ctx.textareaControl.dirty || ctx.textareaControl.touched));
            i0.ɵɵadvance();
            i0.ɵɵproperty("ngClass", i0.ɵɵpureFunction1(10, _c1, ctx.textareaControl.errors && (ctx.textareaControl.dirty || ctx.textareaControl.touched)))("id", ctx.id())("formControl", ctx.textareaControl);
        } }, dependencies: [i2.NgClass, i2.NgIf, i3.DefaultValueAccessor, i3.NgControlStatus, i3.FormControlDirective, i4.FieldLabelPipe, i5.FirstErrorPipe, i6.RpxTranslatePipe], encapsulation: 2 });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(WriteTextAreaFieldComponent, [{
        type: Component,
        args: [{ selector: 'ccd-write-text-area-field', providers: [BrowserService], template: "<div class=\"form-group\" [ngClass]=\"{'form-group-error': !textareaControl.valid && textareaControl.dirty}\">\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=\"textareaControl.errors && (textareaControl.dirty || textareaControl.touched)\">\n    {{textareaControl.errors | ccdFirstError:caseField.label}}\n  </span>\n\n  <textarea (input)=\"autoGrow($event)\" class=\"form-control bottom-30\" [ngClass]=\"{'govuk-textarea--error': textareaControl.errors && (textareaControl.dirty || textareaControl.touched)}\"\n   [id]=\"id()\" rows=\"3\" [formControl]=\"textareaControl\"></textarea>\n</div>\n" }]
    }], () => [{ type: i1.BrowserService }], null); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(WriteTextAreaFieldComponent, { className: "WriteTextAreaFieldComponent", filePath: "lib/shared/components/palette/text-area/write-text-area-field.component.ts", lineNumber: 11 }); })();
//# sourceMappingURL=data:application/json;base64, 