import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { UntypedFormControl, Validators } from '@angular/forms';
// import { LoginService } from '../../services/login/login.service';
import { AppValidators } from '../questionnaire/AppValidators';
import * as i0 from "@angular/core";
import * as i1 from "../../services/logger/logger.service";
import * as i2 from "@angular/router";
import * as i3 from "../../services/util/util.service";
import * as i4 from "@ionic/angular";
import * as i5 from "@angular/common";
import * as i6 from "primeng/api";
import * as i7 from "@angular/forms";
import * as i8 from "primeng/dialog";
import * as i9 from "primeng/inputtext";
import * as i10 from "../error/error.component";
const _c0 = ["qeFormDirective"];
function OfflineLegalDisclaimarComponent_div_2_ng_template_8_div_0_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div", 19)(1, "ion-row");
    i0.ɵɵelement(2, "ion-col", 20);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(3, "ion-row");
    i0.ɵɵelement(4, "ion-col", 21);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(5, "ion-row")(6, "ion-col", 22);
    i0.ɵɵtext(7, "I have read and understand the above statements. Sign with the last four digits of your social security number.");
    i0.ɵɵelement(8, "br");
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext(3);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("innerHTML", ctx_r3.legalDisclaimar.notifyEmployer, i0.ɵɵsanitizeHtml);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("innerHTML", ctx_r3.legalDisclaimar.claimantGuide, i0.ɵɵsanitizeHtml);
} }
function OfflineLegalDisclaimarComponent_div_2_ng_template_8_div_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "div")(1, "ion-row")(2, "ion-col", 22);
    i0.ɵɵtext(3, "I have read and understand the above statements. Sign with the last four digits of your social security number.");
    i0.ɵɵelement(4, "br");
    i0.ɵɵelementEnd()()();
} }
const _c1 = "Last 4 number of entered SSN doesn't match with your SSN's last 4 number.";
const _c2 = () => ({ required: "Required.", notEqual: _c1 });
function OfflineLegalDisclaimarComponent_div_2_ng_template_8_app_error_6_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "app-error", 8);
} if (rf & 2) {
    const ctx_r5 = i0.ɵɵnextContext(3);
    const _r0 = i0.ɵɵreference(1);
    i0.ɵɵclassMap("app-grid");
    i0.ɵɵproperty("field", ctx_r5.lastfourssn)("form", _r0)("errDef", i0.ɵɵpureFunction0(5, _c2));
} }
function OfflineLegalDisclaimarComponent_div_2_ng_template_8_Template(rf, ctx) { if (rf & 1) {
    const _r7 = i0.ɵɵgetCurrentView();
    i0.ɵɵtemplate(0, OfflineLegalDisclaimarComponent_div_2_ng_template_8_div_0_Template, 9, 2, "div", 12)(1, OfflineLegalDisclaimarComponent_div_2_ng_template_8_div_1_Template, 5, 0, "div", 2);
    i0.ɵɵelementStart(2, "ion-row")(3, "ion-col", 13);
    i0.ɵɵelement(4, "input", 14)(5, "br");
    i0.ɵɵtemplate(6, OfflineLegalDisclaimarComponent_div_2_ng_template_8_app_error_6_Template, 1, 6, "app-error", 15);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(7, "ion-col", 16)(8, "ion-button", 17);
    i0.ɵɵlistener("click", function OfflineLegalDisclaimarComponent_div_2_ng_template_8_Template_ion_button_click_8_listener() { i0.ɵɵrestoreView(_r7); const ctx_r6 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r6.cancelDisclaimar()); });
    i0.ɵɵtext(9);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(10, "ion-button", 18);
    i0.ɵɵlistener("click", function OfflineLegalDisclaimarComponent_div_2_ng_template_8_Template_ion_button_click_10_listener() { i0.ɵɵrestoreView(_r7); const ctx_r8 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r8.acceptDisclaimar()); });
    i0.ɵɵtext(11);
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const ctx_r2 = i0.ɵɵnextContext(2);
    const _r0 = i0.ɵɵreference(1);
    i0.ɵɵproperty("ngIf", ctx_r2.util.isState("CT"));
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", !ctx_r2.util.isState("CT"));
    i0.ɵɵadvance(3);
    i0.ɵɵproperty("formControl", ctx_r2.lastfourssn);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", _r0.touched || ctx_r2.isSubmitted);
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", ctx_r2.legalDisclaimar.cancelButton, " ");
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", ctx_r2.legalDisclaimar.acceptButton, " ");
} }
const _c3 = () => ({ width: "60vw" });
const _c4 = () => ({ "960px": "80vw", "640px": "100vw" });
function OfflineLegalDisclaimarComponent_div_2_Template(rf, ctx) { if (rf & 1) {
    const _r10 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "div")(1, "p-dialog", 9);
    i0.ɵɵlistener("visibleChange", function OfflineLegalDisclaimarComponent_div_2_Template_p_dialog_visibleChange_1_listener($event) { i0.ɵɵrestoreView(_r10); const ctx_r9 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r9.displayPosition = $event); });
    i0.ɵɵelementStart(2, "h1");
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelement(4, "div", 10);
    i0.ɵɵelementStart(5, "h1");
    i0.ɵɵtext(6);
    i0.ɵɵelementEnd();
    i0.ɵɵelement(7, "div", 10);
    i0.ɵɵtemplate(8, OfflineLegalDisclaimarComponent_div_2_ng_template_8_Template, 12, 6, "ng-template", 11);
    i0.ɵɵelementEnd()();
} if (rf & 2) {
    const ctx_r1 = i0.ɵɵnextContext();
    i0.ɵɵadvance(1);
    i0.ɵɵstyleMap(i0.ɵɵpureFunction0(10, _c3));
    i0.ɵɵproperty("visible", ctx_r1.displayPosition)("position", ctx_r1.position)("showHeader", false)("breakpoints", i0.ɵɵpureFunction0(11, _c4));
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r1.legalDisclaimar.privacyStatementTitle);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("innerHTML", ctx_r1.legalDisclaimar.privacyStatement, i0.ɵɵsanitizeHtml);
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate(ctx_r1.legalDisclaimar.benefitRightsTitle);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("innerHTML", ctx_r1.legalDisclaimar.benefitRights, i0.ɵɵsanitizeHtml);
} }
const _c5 = () => ({ required: "required." });
export class OfflineLegalDisclaimarComponent {
    constructor(logger, activatedRoute, util) {
        this.logger = logger;
        this.activatedRoute = activatedRoute;
        this.util = util;
        this.displayCheckBox = false;
        this.accepted = new EventEmitter();
        this.isSubmitted = false;
    }
    showPositionDialog(position) {
        this.position = position;
        this.displayPosition = true;
    }
    acceptDisclaimar() {
        this.isSubmitted = true;
        if (this.lastfourssn.valid) {
            this.displayCheckBox = true;
            this.accepted.emit(true);
            this.displayPosition = false;
            this.legalHidden.setValue(true);
        }
    }
    cancelDisclaimar() {
        this.isSubmitted = false;
        this.displayCheckBox = false;
        this.accepted.emit(false);
        this.legalHidden.setValue(null);
        this.displayPosition = false;
    }
    get legalHidden() {
        return this.form.get('legalHidden');
    }
    get lastfourssn() {
        return this.form.get('lastfourssn');
    }
    //   ngOnInit() {
    //     const storedData = localStorage.getItem('clmtaboutyourselfdata');
    //     let ssnLastFourFromDb: string = '0000';
    //     if (storedData) {
    //       const parsed = JSON.parse(storedData);
    //       if (parsed.ssn) {
    //         ssnLastFourFromDb = parsed.ssn.slice(-4);
    //       }
    //     }
    //     this.form.addControl('legalHidden', new UntypedFormControl(null, [Validators.requiredTrue]));
    //     this.form.addControl('lastfourssn', new UntypedFormControl(null, [
    //       Validators.required,
    //       AppValidators.isEqual(ssnLastFourFromDb)
    //     ]));
    //     this.question.name = 'legalHidden';
    //     const obj = JSON.parse(this.componentData);
    //     this.legalDisclaimar = obj;
    //   }
    ngOnInit() {
        const storedData = localStorage.getItem('clmtabtyourselfdata');
        let ssnLastFourFromDb = '0000'; // fallback default
        if (storedData) {
            try {
                const parsed = JSON.parse(storedData);
                const rawSSN = parsed?.ssnConfirm || parsed?.ssn;
                if (rawSSN) {
                    const digitsOnly = rawSSN.replace(/\D/g, ''); // remove dashes
                    ssnLastFourFromDb = digitsOnly.slice(-4);
                    console.log('Extracted SSN Last 4:', ssnLastFourFromDb);
                }
                else {
                    console.warn('No valid SSN or ssnConfirm found.');
                }
            }
            catch (err) {
                console.error('Failed to parse SSN JSON:', err);
            }
        }
        else {
            console.warn('clmtaboutyourselfdata not found in localStorage');
        }
        // Use the extracted value in validator
        this.form.addControl('legalHidden', new UntypedFormControl(null, [Validators.requiredTrue]));
        this.form.addControl('lastfourssn', new UntypedFormControl(null, [
            Validators.required,
            AppValidators.isEqual(ssnLastFourFromDb)
        ]));
        this.question.name = 'legalHidden';
        try {
            const obj = JSON.parse(this.componentData);
            this.legalDisclaimar = obj;
        }
        catch (err) {
            console.error('Failed to parse componentData', err);
        }
    }
    static { this.ɵfac = function OfflineLegalDisclaimarComponent_Factory(t) { return new (t || OfflineLegalDisclaimarComponent)(i0.ɵɵdirectiveInject(i1.LoggerService), i0.ɵɵdirectiveInject(i2.ActivatedRoute), i0.ɵɵdirectiveInject(i3.UtilService)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: OfflineLegalDisclaimarComponent, selectors: [["app-offline-legal-disclaimar"]], viewQuery: function OfflineLegalDisclaimarComponent_Query(rf, ctx) { if (rf & 1) {
            i0.ɵɵviewQuery(_c0, 5);
        } if (rf & 2) {
            let _t;
            i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.qeFormDirective = _t.first);
        } }, inputs: { form: "form", question: "question", componentData: "componentData" }, outputs: { accepted: "accepted" }, decls: 11, vars: 8, consts: [[3, "formGroup"], ["qeFormDirective", "ngForm"], [4, "ngIf"], [1, "form-label"], [1, "grid", "p-nogutter"], [1, "col-12"], ["shape", "round", "type", "submit", "fill", "outline", 3, "click"], ["slot", "start", 2, "font-size", "25px", "font-weight", "bold", 3, "name"], [3, "field", "form", "errDef"], ["modal", "true", "appendTo", "body", 3, "visible", "position", "showHeader", "breakpoints", "visibleChange"], [3, "innerHTML"], ["pTemplate", "footer"], ["class", "scroll", 4, "ngIf"], [1, "ion-text-left"], ["id", "ssn", "type", "input", "pInputText", "", "size", "5", "maxlength", "4", "minlength", "4", 3, "formControl"], [3, "class", "field", "form", "errDef", 4, "ngIf"], [1, "ion-text-right"], ["shape", "round", "type", "reset", "fill", "outline", 3, "click"], ["shape", "round", "type", "submit", "fill", "solid", 3, "click"], [1, "scroll"], [1, "ion-text-left", 3, "innerHTML"], [1, "ion-text-left", "ion-padding-top", 3, "innerHTML"], [1, "ion-text-left", "ion-padding-top"]], template: function OfflineLegalDisclaimarComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "form", 0, 1);
            i0.ɵɵtemplate(2, OfflineLegalDisclaimarComponent_div_2_Template, 9, 12, "div", 2);
            i0.ɵɵelementStart(3, "p", 3);
            i0.ɵɵtext(4);
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(5, "div", 4)(6, "div", 5)(7, "ion-button", 6);
            i0.ɵɵlistener("click", function OfflineLegalDisclaimarComponent_Template_ion_button_click_7_listener() { return ctx.showPositionDialog("top"); });
            i0.ɵɵelement(8, "ion-icon", 7);
            i0.ɵɵtext(9, " Disclaimers ");
            i0.ɵɵelementEnd();
            i0.ɵɵelement(10, "app-error", 8);
            i0.ɵɵelementEnd()()();
        } if (rf & 2) {
            const _r0 = i0.ɵɵreference(1);
            i0.ɵɵproperty("formGroup", ctx.form);
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("ngIf", ctx.legalDisclaimar);
            i0.ɵɵadvance(2);
            i0.ɵɵtextInterpolate1(" ", ctx.legalDisclaimar.plsRead, "");
            i0.ɵɵadvance(4);
            i0.ɵɵproperty("name", ctx.displayCheckBox ? "checkmark-circle-outline" : "ellipse-outline");
            i0.ɵɵadvance(2);
            i0.ɵɵproperty("field", ctx.legalHidden)("form", _r0)("errDef", i0.ɵɵpureFunction0(7, _c5));
        } }, dependencies: [i4.IonButton, i4.IonCol, i4.IonIcon, i4.IonRow, i5.NgIf, i6.PrimeTemplate, i7.ɵNgNoValidate, i7.DefaultValueAccessor, i7.NgControlStatus, i7.NgControlStatusGroup, i7.MinLengthValidator, i7.MaxLengthValidator, i7.FormControlDirective, i7.FormGroupDirective, i8.Dialog, i9.InputText, i10.ErrorComponent], styles: [".form-label[_ngcontent-%COMP%]{display:inline-block;margin-bottom:6px;margin-top:20px}div.scroll[_ngcontent-%COMP%]{width:58.5vw;height:110px;overflow-x:hidden;overflow-y:scroll}"] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(OfflineLegalDisclaimarComponent, [{
        type: Component,
        args: [{ selector: 'app-offline-legal-disclaimar', template: "<form [formGroup]=\"form\" #qeFormDirective=\"ngForm\">\r\n  <div *ngIf=\"legalDisclaimar\">\r\n\r\n    <p-dialog [(visible)]=\"displayPosition\" [position]=\"position\" modal=\"true\" [showHeader]=\"false\" appendTo=\"body\"\r\n      [breakpoints]=\"{'960px': '80vw', '640px': '100vw'}\" [style]=\"{width: '60vw'}\">\r\n\r\n      <h1>{{legalDisclaimar.privacyStatementTitle}}</h1>\r\n      <div [innerHTML]=\"legalDisclaimar.privacyStatement\"></div>\r\n      <h1>{{legalDisclaimar.benefitRightsTitle}}</h1>\r\n      <div [innerHTML]=\"legalDisclaimar.benefitRights\"></div>\r\n\r\n      <ng-template pTemplate=\"footer\">\r\n\r\n        <div class=\"scroll\" *ngIf=\"util.isState('CT')\">\r\n          <ion-row>\r\n            <ion-col class=\"ion-text-left\" [innerHTML]=\"legalDisclaimar.notifyEmployer\"></ion-col>\r\n          </ion-row>\r\n          <ion-row>\r\n            <ion-col class=\"ion-text-left ion-padding-top\" [innerHTML]=\"legalDisclaimar.claimantGuide\"></ion-col>\r\n          </ion-row>\r\n          <ion-row>\r\n            <ion-col class=\"ion-text-left ion-padding-top\">I have read and understand the above statements. Sign with\r\n              the last four digits of your social security number.<br />\r\n            </ion-col>\r\n          </ion-row>\r\n        </div>\r\n\r\n        <div *ngIf=\"!util.isState('CT')\">\r\n          <ion-row>\r\n            <ion-col class=\"ion-text-left ion-padding-top\">I have read and understand the above statements. Sign with\r\n              the last four digits of your social security number.<br />\r\n            </ion-col>\r\n          </ion-row>\r\n        </div>\r\n        <ion-row>\r\n\r\n          <ion-col class=\"ion-text-left\">\r\n            <input id=\"ssn\" type=\"input\" pInputText size=\"5\" [formControl]=\"lastfourssn\" maxlength=\"4\" minlength=\"4\" />\r\n            <br />\r\n            <app-error [class]=\"'app-grid'\" [field]='lastfourssn' [form]=\"qeFormDirective\" [errDef]=\"{\r\n              required: 'Required.',\r\n              notEqual: 'Last 4 number of entered SSN doesn\\'t match with your SSN\\'s last 4 number.'\r\n            }\" *ngIf=\"this.qeFormDirective.touched || isSubmitted\"></app-error>\r\n          </ion-col>\r\n          <ion-col class=\"ion-text-right\">\r\n            <ion-button shape=\"round\" (click)=\"cancelDisclaimar()\" type=\"reset\" fill=\"outline\">\r\n              {{legalDisclaimar.cancelButton}}\r\n            </ion-button>\r\n            <ion-button shape=\"round\" type=\"submit\" (click)=\"acceptDisclaimar()\" fill=\"solid\">\r\n              {{legalDisclaimar.acceptButton}}\r\n            </ion-button>\r\n          </ion-col>\r\n        </ion-row>\r\n      </ng-template>\r\n    </p-dialog>\r\n  </div>\r\n  <p class=\"form-label\"> {{legalDisclaimar.plsRead}}</p>\r\n  <div class=\"grid p-nogutter\">\r\n    <div class=\"col-12\">\r\n      <!-- <input type=\"text\" id=\"legalHidden\" pInputText formControlName=\"legalHidden\" hidden /> -->\r\n      <ion-button shape=\"round\" (click)=\"showPositionDialog('top')\" type=\"submit\" fill=\"outline\">\r\n        <ion-icon slot=\"start\" [name]=\"displayCheckBox ? 'checkmark-circle-outline' : 'ellipse-outline'\"\r\n          style=\"font-size: 25px; font-weight: bold;\"></ion-icon>\r\n        Disclaimers\r\n      </ion-button>\r\n      <app-error [field]='legalHidden' [form]=\"qeFormDirective\" [errDef]=\"{\r\n          required: 'required.'\r\n        }\"></app-error>\r\n    </div>\r\n  </div>\r\n\r\n</form>", styles: [".form-label{display:inline-block;margin-bottom:6px;margin-top:20px}div.scroll{width:58.5vw;height:110px;overflow-x:hidden;overflow-y:scroll}\n"] }]
    }], () => [{ type: i1.LoggerService }, { type: i2.ActivatedRoute }, { type: i3.UtilService }], { qeFormDirective: [{
            type: ViewChild,
            args: ['qeFormDirective', { static: false }]
        }], accepted: [{
            type: Output
        }], form: [{
            type: Input
        }], question: [{
            type: Input
        }], componentData: [{
            type: Input
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(OfflineLegalDisclaimarComponent, { className: "OfflineLegalDisclaimarComponent", filePath: "lib\\components\\offline-legal-disclaimar\\offline-legal-disclaimar.component.ts", lineNumber: 19 }); })();
//# sourceMappingURL=data:application/json;base64, 