import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FormControl } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { QualifyingQuestionsErrorMessage } from '../../../enums';
import { QualifyingQuestionService } from '../../../services';
import * as i0 from "@angular/core";
import * as i1 from "@angular/router";
import * as i2 from "../../../services";
import * as i3 from "@angular/common";
import * as i4 from "@angular/forms";
import * as i5 from "rpx-xui-translation";
function QualifyingQuestionOptionsComponent_ng_container_0_ng_container_10_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "p", 8)(2, "span", 9);
    i0.ɵɵtext(3);
    i0.ɵɵpipe(4, "rpxTranslate");
    i0.ɵɵelementEnd();
    i0.ɵɵtext(5);
    i0.ɵɵpipe(6, "rpxTranslate");
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1("", i0.ɵɵpipeBind1(4, 2, "Error:"), " ");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1("", i0.ɵɵpipeBind1(6, 4, ctx_r0.qualifyingQuestionsErrorMessage.SELECT_AN_OPTION), " ");
} }
function QualifyingQuestionOptionsComponent_ng_container_0_ng_container_12_ng_container_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "div", 13);
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "rpxTranslate");
    i0.ɵɵelementEnd();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(3, 1, "If your issue is not covered by the options above, raise a query:"));
} }
function QualifyingQuestionOptionsComponent_ng_container_0_ng_container_12_Template(rf, ctx) { if (rf & 1) {
    const _r2 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, QualifyingQuestionOptionsComponent_ng_container_0_ng_container_12_ng_container_1_Template, 4, 3, "ng-container", 0);
    i0.ɵɵelementStart(2, "div", 10)(3, "input", 11);
    i0.ɵɵlistener("change", function QualifyingQuestionOptionsComponent_ng_container_0_ng_container_12_Template_input_change_3_listener() { const qualifyingQuestion_r3 = i0.ɵɵrestoreView(_r2).$implicit; const ctx_r0 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r0.onSelectionChange(qualifyingQuestion_r3)); });
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "label", 12);
    i0.ɵɵtext(5);
    i0.ɵɵpipe(6, "rpxTranslate");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const qualifyingQuestion_r3 = ctx.$implicit;
    const isLast_r4 = ctx.last;
    const ctx_r0 = i0.ɵɵnextContext(2);
    i0.ɵɵadvance();
    i0.ɵɵproperty("ngIf", isLast_r4);
    i0.ɵɵadvance(2);
    i0.ɵɵpropertyInterpolate("id", qualifyingQuestion_r3.name);
    i0.ɵɵproperty("formControl", ctx_r0.qualifyingQuestionsControl)("value", qualifyingQuestion_r3);
    i0.ɵɵadvance();
    i0.ɵɵproperty("for", qualifyingQuestion_r3.name);
    i0.ɵɵadvance();
    i0.ɵɵtextInterpolate(i0.ɵɵpipeBind1(6, 6, qualifyingQuestion_r3.name));
} }
function QualifyingQuestionOptionsComponent_ng_container_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵelementStart(1, "div", 1)(2, "fieldset", 2)(3, "legend", 3)(4, "h1", 4);
    i0.ɵɵtext(5);
    i0.ɵɵpipe(6, "rpxTranslate");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(7, "h2", 5);
    i0.ɵɵtext(8);
    i0.ɵɵpipe(9, "rpxTranslate");
    i0.ɵɵelementEnd();
    i0.ɵɵtemplate(10, QualifyingQuestionOptionsComponent_ng_container_0_ng_container_10_Template, 7, 6, "ng-container", 0);
    i0.ɵɵelementStart(11, "div", 6);
    i0.ɵɵtemplate(12, QualifyingQuestionOptionsComponent_ng_container_0_ng_container_12_Template, 7, 8, "ng-container", 7);
    i0.ɵɵpipe(13, "async");
    i0.ɵɵelementEnd()()();
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const ctx_r0 = i0.ɵɵnextContext();
    i0.ɵɵadvance();
    i0.ɵɵclassProp("govuk-form-group--error", ctx_r0.displayError);
    i0.ɵɵadvance(4);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(6, 6, "Raise a new query"), " ");
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(9, 8, "What do you need help to do?"), " ");
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", ctx_r0.displayError);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngForOf", i0.ɵɵpipeBind1(13, 10, ctx_r0.qualifyingQuestions$));
} }
export class QualifyingQuestionOptionsComponent {
    route;
    router;
    qualifyingQuestionService;
    qualifyingQuestionsControl;
    qualifyingQuestions$;
    questionSelected = new EventEmitter();
    qualifyingQuestionsErrorMessage = QualifyingQuestionsErrorMessage;
    caseId;
    jurisdiction;
    caseType;
    constructor(route, router, qualifyingQuestionService) {
        this.route = route;
        this.router = router;
        this.qualifyingQuestionService = qualifyingQuestionService;
    }
    ngOnInit() {
        this.caseId = this.route.snapshot.params.cid;
        this.jurisdiction = this.route.snapshot.params.jurisdiction;
        this.caseType = this.route.snapshot.params.caseType;
        // Check if there's already a selected qualifying question from the service
        const savedSelection = this.qualifyingQuestionService.getQualifyingQuestionSelection();
        if (savedSelection) {
            this.qualifyingQuestionsControl.setValue(savedSelection);
        }
    }
    click() {
        this.router.navigate(['cases', 'case-details', this.jurisdiction, this.caseType, this.caseId], { fragment: 'Queries' });
    }
    get displayError() {
        return this.qualifyingQuestionsControl.touched && this.qualifyingQuestionsControl.hasError('required');
    }
    onSelectionChange(qualifyingQuestion) {
        this.questionSelected.emit(qualifyingQuestion);
    }
    static ɵfac = function QualifyingQuestionOptionsComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || QualifyingQuestionOptionsComponent)(i0.ɵɵdirectiveInject(i1.ActivatedRoute), i0.ɵɵdirectiveInject(i1.Router), i0.ɵɵdirectiveInject(i2.QualifyingQuestionService)); };
    static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: QualifyingQuestionOptionsComponent, selectors: [["ccd-qualifying-question-options"]], inputs: { qualifyingQuestionsControl: "qualifyingQuestionsControl", qualifyingQuestions$: "qualifyingQuestions$" }, outputs: { questionSelected: "questionSelected" }, decls: 1, vars: 1, consts: [[4, "ngIf"], [1, "govuk-form-group"], [1, "govuk-fieldset"], [1, "govuk-fieldset__legend", "govuk-fieldset__legend--l"], [1, "govuk-fieldset__heading"], [1, "govuk-heading-m", "govuk-!-margin-top-10"], ["data-module", "govuk-radios", 1, "govuk-radios"], [4, "ngFor", "ngForOf"], [1, "govuk-error-message"], [1, "govuk-visually-hidden"], [1, "govuk-radios__item"], ["name", "qualifyingQuestionOption", "type", "radio", 1, "govuk-radios__input", 3, "change", "id", "formControl", "value"], [1, "govuk-label", "govuk-radios__label", 3, "for"], [1, "qm-qualifying-question__divider"]], template: function QualifyingQuestionOptionsComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵtemplate(0, QualifyingQuestionOptionsComponent_ng_container_0_Template, 14, 12, "ng-container", 0);
        } if (rf & 2) {
            i0.ɵɵproperty("ngIf", ctx.qualifyingQuestionsControl);
        } }, dependencies: [i3.NgForOf, i3.NgIf, i4.DefaultValueAccessor, i4.RadioControlValueAccessor, i4.NgControlStatus, i4.FormControlDirective, i3.AsyncPipe, i5.RpxTranslatePipe], encapsulation: 2 });
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(QualifyingQuestionOptionsComponent, [{
        type: Component,
        args: [{ selector: 'ccd-qualifying-question-options', template: "<ng-container *ngIf=\"qualifyingQuestionsControl\">\n  <div class=\"govuk-form-group\" [class.govuk-form-group--error]=\"displayError\">\n    <fieldset class=\"govuk-fieldset\">\n      <legend class=\"govuk-fieldset__legend govuk-fieldset__legend--l\">\n        <h1 class=\"govuk-fieldset__heading\">\n          {{ 'Raise a new query' | rpxTranslate }}\n        </h1>\n      </legend>\n      <h2 class=\"govuk-heading-m govuk-!-margin-top-10\">\n        {{ 'What do you need help to do?' | rpxTranslate }}\n      </h2>\n\n      <ng-container *ngIf=\"displayError\">\n        <p class=\"govuk-error-message\">\n          <span class=\"govuk-visually-hidden\">{{ 'Error:' | rpxTranslate }} </span>{{\n          qualifyingQuestionsErrorMessage.SELECT_AN_OPTION | rpxTranslate }}\n        </p>\n      </ng-container>\n\n      <div class=\"govuk-radios\" data-module=\"govuk-radios\">\n        <ng-container *ngFor=\"let qualifyingQuestion of qualifyingQuestions$ | async; let isLast = last\">\n          <ng-container *ngIf=\"isLast\">\n            <div class=\"qm-qualifying-question__divider\">{{ 'If your issue is not covered by the options above, raise a query:' | rpxTranslate }}</div>\n          </ng-container>\n          <div class=\"govuk-radios__item\">\n            <input class=\"govuk-radios__input\" \n              id=\"{{qualifyingQuestion.name}}\" \n              name=\"qualifyingQuestionOption\"\n              type=\"radio\" [formControl]=\"qualifyingQuestionsControl\" \n              [value]=\"qualifyingQuestion\"\n              (change)=\"onSelectionChange(qualifyingQuestion)\">\n            <label class=\"govuk-label govuk-radios__label\" [for]=\"qualifyingQuestion.name\">{{ qualifyingQuestion.name |\n              rpxTranslate }}</label>\n          </div>\n        </ng-container>\n      </div>\n    </fieldset>\n  </div>\n</ng-container>\n" }]
    }], () => [{ type: i1.ActivatedRoute }, { type: i1.Router }, { type: i2.QualifyingQuestionService }], { qualifyingQuestionsControl: [{
            type: Input
        }], qualifyingQuestions$: [{
            type: Input
        }], questionSelected: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(QualifyingQuestionOptionsComponent, { className: "QualifyingQuestionOptionsComponent", filePath: "lib/shared/components/palette/query-management/components/qualifying-questions/qualifying-question-options/qualifying-question-options.component.ts", lineNumber: 13 }); })();
//# sourceMappingURL=data:application/json;base64, 