import { Component, EventEmitter, Output, Input, ChangeDetectionStrategy } from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import * as i0 from "@angular/core";
import * as i1 from "../../services/logger/logger.service";
import * as i2 from "../../services/questionnaire/validation.service";
import * as i3 from "@ionic/angular";
import * as i4 from "@angular/common";
import * as i5 from "primeng/api";
import * as i6 from "primeng/dialog";
import * as i7 from "primeng/table";
import * as i8 from "@fortawesome/angular-fontawesome";
import * as i9 from "../employer-pay/employer-pay.component";
import * as i10 from "@ngx-translate/core";
function EmployerPayGridComponent_ng_template_7_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "tr", 11)(1, "th", 12);
    i0.ɵɵtext(2);
    i0.ɵɵpipe(3, "translate");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "th");
    i0.ɵɵtext(5);
    i0.ɵɵpipe(6, "translate");
    i0.ɵɵelementEnd();
    i0.ɵɵelement(7, "th");
    i0.ɵɵelementEnd();
} if (rf & 2) {
    i0.ɵɵadvance(2);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(3, 2, "employer.pay.grid.header.employer"), " ");
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", i0.ɵɵpipeBind1(6, 4, "employer.pay.grid.header.payType"), " ");
} }
function EmployerPayGridComponent_ng_template_8_ng_container_9_span_1_br_8_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelement(0, "br");
} }
function EmployerPayGridComponent_ng_template_8_ng_container_9_span_1_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementStart(0, "span")(1, "tr")(2, "td", 20);
    i0.ɵɵtext(3);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "td")(5, "b");
    i0.ɵɵtext(6);
    i0.ɵɵpipe(7, "currency");
    i0.ɵɵelementEnd()()();
    i0.ɵɵtemplate(8, EmployerPayGridComponent_ng_template_8_ng_container_9_span_1_br_8_Template, 1, 0, "br", 19);
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r14 = i0.ɵɵnextContext();
    const payType_r10 = ctx_r14.$implicit;
    const last_r11 = ctx_r14.last;
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(" ", payType_r10.payType.text, " ");
    i0.ɵɵadvance(3);
    i0.ɵɵtextInterpolate1(": ", i0.ɵɵpipeBind1(7, 3, payType_r10.amount), "");
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("ngIf", !last_r11);
} }
function EmployerPayGridComponent_ng_template_8_ng_container_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵelementContainerStart(0);
    i0.ɵɵtemplate(1, EmployerPayGridComponent_ng_template_8_ng_container_9_span_1_Template, 9, 5, "span", 19);
    i0.ɵɵelementContainerEnd();
} if (rf & 2) {
    const payType_r10 = ctx.$implicit;
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("ngIf", payType_r10.isChecked);
} }
const _c0 = () => ["fal", "edit"];
const _c1 = () => ["fal", "trash-alt"];
function EmployerPayGridComponent_ng_template_8_Template(rf, ctx) { if (rf & 1) {
    const _r16 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "tr", 11)(1, "td", 12)(2, "span", 13);
    i0.ɵɵtext(3, "Employer");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(4, "span");
    i0.ɵɵtext(5);
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(6, "td")(7, "span", 13);
    i0.ɵɵtext(8, "Pay Type");
    i0.ɵɵelementEnd();
    i0.ɵɵtemplate(9, EmployerPayGridComponent_ng_template_8_ng_container_9_Template, 2, 1, "ng-container", 14);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(10, "td", 15)(11, "ion-button", 16);
    i0.ɵɵlistener("click", function EmployerPayGridComponent_ng_template_8_Template_ion_button_click_11_listener() { const restoredCtx = i0.ɵɵrestoreView(_r16); const employer_r7 = restoredCtx.$implicit; const ctx_r15 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r15.editEmployerPayment(employer_r7)); });
    i0.ɵɵelement(12, "fa-icon", 17);
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(13, "ion-button", 18);
    i0.ɵɵlistener("click", function EmployerPayGridComponent_ng_template_8_Template_ion_button_click_13_listener() { const restoredCtx = i0.ɵɵrestoreView(_r16); const rowIndex_r8 = restoredCtx.rowIndex; const ctx_r17 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r17.deleteEmployerPayment(rowIndex_r8)); });
    i0.ɵɵelement(14, "fa-icon", 17);
    i0.ɵɵelementEnd()()();
} if (rf & 2) {
    const employer_r7 = ctx.$implicit;
    const rowIndex_r8 = ctx.rowIndex;
    i0.ɵɵadvance(5);
    i0.ɵɵtextInterpolate1(" ", employer_r7.employerName, "");
    i0.ɵɵadvance(4);
    i0.ɵɵproperty("ngForOf", employer_r7.payTypes);
    i0.ɵɵadvance(2);
    i0.ɵɵproperty("id", "btnEditEmployerPayment-" + rowIndex_r8);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("icon", i0.ɵɵpureFunction0(6, _c0));
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("id", "btnDeleteEmployerPayment-" + rowIndex_r8);
    i0.ɵɵadvance(1);
    i0.ɵɵproperty("icon", i0.ɵɵpureFunction0(7, _c1));
} }
const _c2 = () => ["fal", "plus"];
function EmployerPayGridComponent_ng_template_9_table_0_Template(rf, ctx) { if (rf & 1) {
    const _r21 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "table")(1, "tr")(2, "td", 21)(3, "div")(4, "b");
    i0.ɵɵtext(5, "+ Add");
    i0.ɵɵelementEnd();
    i0.ɵɵtext(6, " Payment");
    i0.ɵɵelementEnd()();
    i0.ɵɵelementStart(7, "td", 22)(8, "ion-button", 23);
    i0.ɵɵlistener("click", function EmployerPayGridComponent_ng_template_9_table_0_Template_ion_button_click_8_listener() { i0.ɵɵrestoreView(_r21); const ctx_r20 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r20.addEmployerPay()); });
    i0.ɵɵelement(9, "fa-icon", 17);
    i0.ɵɵelementEnd()()()();
} if (rf & 2) {
    i0.ɵɵadvance(2);
    i0.ɵɵattribute("colspan", 4);
    i0.ɵɵadvance(7);
    i0.ɵɵproperty("icon", i0.ɵɵpureFunction0(2, _c2));
} }
function EmployerPayGridComponent_ng_template_9_Template(rf, ctx) { if (rf & 1) {
    i0.ɵɵtemplate(0, EmployerPayGridComponent_ng_template_9_table_0_Template, 10, 3, "table", 19);
} if (rf & 2) {
    const ctx_r3 = i0.ɵɵnextContext();
    i0.ɵɵproperty("ngIf", !ctx_r3.selected);
} }
function EmployerPayGridComponent_app_employer_pay_10_Template(rf, ctx) { if (rf & 1) {
    const _r23 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "app-employer-pay", 24);
    i0.ɵɵlistener("success", function EmployerPayGridComponent_app_employer_pay_10_Template_app_employer_pay_success_0_listener($event) { i0.ɵɵrestoreView(_r23); const ctx_r22 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r22.addEmployerPayment($event)); })("onClose", function EmployerPayGridComponent_app_employer_pay_10_Template_app_employer_pay_onClose_0_listener() { i0.ɵɵrestoreView(_r23); const ctx_r24 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r24.close()); });
    i0.ɵɵelementEnd();
} if (rf & 2) {
    const ctx_r4 = i0.ɵɵnextContext();
    i0.ɵɵproperty("empToEdit", ctx_r4.selectedEmployer);
} }
function EmployerPayGridComponent_ng_template_16_Template(rf, ctx) { if (rf & 1) {
    const _r26 = i0.ɵɵgetCurrentView();
    i0.ɵɵelementStart(0, "ion-button", 25);
    i0.ɵɵlistener("click", function EmployerPayGridComponent_ng_template_16_Template_ion_button_click_0_listener() { i0.ɵɵrestoreView(_r26); const ctx_r25 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r25.close()); });
    i0.ɵɵtext(1, " Close ");
    i0.ɵɵelementEnd();
    i0.ɵɵelementStart(2, "ion-button", 26);
    i0.ɵɵlistener("click", function EmployerPayGridComponent_ng_template_16_Template_ion_button_click_2_listener() { i0.ɵɵrestoreView(_r26); const ctx_r27 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r27.editDuplicateEmployer()); });
    i0.ɵɵtext(3, " Edit ");
    i0.ɵɵelementEnd();
} }
const _c3 = () => ({ width: "45vw" });
const _c4 = () => ({ "1200px": "660px", "992px": "660px", "768px": "660px", "576px": "100vw" });
export class EmployerPayGridComponent {
    constructor(logger, vs) {
        this.logger = logger;
        this.vs = vs;
        this.selected = false;
        this.indexToEdit = null;
        this.activeIndex = null;
        this.showDuplicatePopup = false;
        this.employerPay = [];
        this.modelDisplay = new EventEmitter();
        this.onChange = (value) => { };
        this.onTouch = () => { };
        this.onChangeSubs = [];
        this.isDisabled = false;
    }
    ngOnInit() {
        this.employerPay = this.vs.employerPayDetails.getValue() || [];
    }
    ngOnDestroy() {
        for (let sub of this.onChangeSubs) {
            sub.unsubscribe();
        }
    }
    writeValue(value) {
        if (value) {
            this.employerPay = value;
            this.publishEmployer();
        }
    }
    registerOnChange(fn) {
        let sub = this.vs.employerPayDetails.subscribe(fn);
        this.onChangeSubs.push(sub);
    }
    registerOnTouched(onTouch) {
        this.onTouch = onTouch;
    }
    setDisabledState(isDisabled) {
        this.isDisabled = isDisabled;
    }
    deleteEmployerPayment(employer) {
        let index = this.employerPay.indexOf(employer);
        this.employerPay.splice(index, 1);
        this.publishEmployer();
    }
    editDuplicateEmployer() {
        this.showDuplicatePopup = false;
        this.display = true;
        this.selected = true;
        this.activeIndex = 0;
    }
    editEmployerPayment(employer) {
        this.selectedEmployer = employer;
        this.indexToEdit = this.employerPay.indexOf(employer);
        this.display = true;
        this.selected = true;
        this.activeIndex = 0;
    }
    async addEmployerPay() {
        this.selected = true;
        this.modelDisplay.emit(true);
    }
    close() {
        this.display = false;
        this.indexToEdit = null;
        this.selectedEmployer = null;
        this.showDuplicatePopup = false;
        this.selected = false;
        this.activeIndex = -1;
    }
    checkForDuplicate(employer) {
        if (this.employerPay) {
            let employerPay = this.employerPay.filter(e => {
                if (this.indexToEdit == this.employerPay.indexOf(e)) {
                    return false;
                }
                let result = (employer.employerName == e.employerName && employer.address.state.text == e.address.state.text && employer.address.city == e.address.city);
                return result;
            });
            return employerPay.length > 0;
        }
        else {
            return false;
        }
    }
    addEmployerPayment(employer) {
        if (this.checkForDuplicate(employer)) {
            this.selectedEmployer = employer;
            this.display = false;
            this.showDuplicatePopup = true;
            return;
        }
        if (this.indexToEdit != null) {
            this.employerPay[this.indexToEdit] = employer;
        }
        else {
            this.employerPay.push(employer);
        }
        this.display = false;
        this.selectedEmployer = null;
        this.indexToEdit = null;
        this.publishEmployer();
        this.selected = false;
        this.activeIndex = -1;
    }
    publishEmployer() {
        this.vs.employerPayDetails.next(this.employerPay.length > 0 ? this.employerPay : null);
    }
    static { this.ɵfac = function EmployerPayGridComponent_Factory(t) { return new (t || EmployerPayGridComponent)(i0.ɵɵdirectiveInject(i1.LoggerService), i0.ɵɵdirectiveInject(i2.ValidationService)); }; }
    static { this.ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: EmployerPayGridComponent, selectors: [["app-employer-pay-grid"]], inputs: { dynamicParam: "dynamicParam" }, outputs: { modelDisplay: "modelDisplay" }, features: [i0.ɵɵProvidersFeature([{
                    provide: NG_VALUE_ACCESSOR,
                    useExisting: EmployerPayGridComponent,
                    multi: true
                }])], decls: 17, vars: 13, consts: [[2, "margin-left", "-5px"], [2, "margin-left", "8px"], ["styleClass", "p-datatable-striped app-datatable ion-padding-top", 3, "rowHover", "value"], ["dt", ""], ["pTemplate", "header"], ["pTemplate", "body"], ["pTemplate", "summary"], [3, "empToEdit", "success", "onClose", 4, "ngIf"], ["appendTo", "body", "position", "top", "appendTo", "body", "closeOnEscape", "false", 3, "visible", "modal", "breakpoints", "baseZIndex", "draggable", "resizable"], [1, "heading"], ["pTemplate", "footer"], [1, "ion-padding-top", "ion-padding-bottom"], [2, "padding-left", "15px"], [1, "p-column-title"], [4, "ngFor", "ngForOf"], [2, "text-align", "center"], ["size", "small", "color", "success", "fill", "outline", "aria-label", "Edit employer payment", 1, "action-button", 3, "id", "click"], [1, "action-icon", 3, "icon"], ["size", "small", "color", "success", "fill", "outline", "aria-label", "Remove employer payment", 1, "action-button", 3, "id", "click"], [4, "ngIf"], [2, "width", "275px", "white-space", "wrap"], [1, "ion-padding-top", 2, "width", "90%"], [1, "ion-padding-top"], ["id", "addEmployerPaymentDetails", "aria-label", "Add Payment Details", "fill", "outline", "size", "small", 1, "action-button", 3, "click"], [3, "empToEdit", "success", "onClose"], ["shape", "round", "size", "small", "type", "submit", "fill", "outline", 3, "click"], ["shape", "round", "size", "small", "type", "submit", "fill", "solid", 3, "click"]], template: function EmployerPayGridComponent_Template(rf, ctx) { if (rf & 1) {
            i0.ɵɵelementStart(0, "div", 0)(1, "div", 1)(2, "b");
            i0.ɵɵtext(3, "+ Add");
            i0.ɵɵelementEnd();
            i0.ɵɵtext(4, " payments from your former employers");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(5, "p-table", 2, 3);
            i0.ɵɵtemplate(7, EmployerPayGridComponent_ng_template_7_Template, 8, 6, "ng-template", 4)(8, EmployerPayGridComponent_ng_template_8_Template, 15, 8, "ng-template", 5)(9, EmployerPayGridComponent_ng_template_9_Template, 1, 1, "ng-template", 6);
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(10, EmployerPayGridComponent_app_employer_pay_10_Template, 1, 1, "app-employer-pay", 7);
            i0.ɵɵelementStart(11, "p-dialog", 8)(12, "h4", 9);
            i0.ɵɵtext(13, "Duplicate employer not allowed");
            i0.ɵɵelementEnd();
            i0.ɵɵelementStart(14, "ion-label");
            i0.ɵɵtext(15, "It seems like you have added a employer that has been added already. Please check details and try adding employer again.");
            i0.ɵɵelementEnd();
            i0.ɵɵtemplate(16, EmployerPayGridComponent_ng_template_16_Template, 4, 0, "ng-template", 10);
            i0.ɵɵelementEnd()();
        } if (rf & 2) {
            i0.ɵɵadvance(5);
            i0.ɵɵproperty("rowHover", true)("value", ctx.employerPay);
            i0.ɵɵadvance(5);
            i0.ɵɵproperty("ngIf", ctx.selected);
            i0.ɵɵadvance(1);
            i0.ɵɵstyleMap(i0.ɵɵpureFunction0(11, _c3));
            i0.ɵɵproperty("visible", ctx.showDuplicatePopup)("modal", true)("breakpoints", i0.ɵɵpureFunction0(12, _c4))("baseZIndex", 5000)("draggable", false)("resizable", false);
        } }, dependencies: [i3.IonButton, i3.IonLabel, i4.NgForOf, i4.NgIf, i5.PrimeTemplate, i6.Dialog, i7.Table, i8.FaIconComponent, i9.EmployerPayComponent, i4.CurrencyPipe, i10.TranslatePipe] }); }
}
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(EmployerPayGridComponent, [{
        type: Component,
        args: [{ selector: 'app-employer-pay-grid', providers: [{
                        provide: NG_VALUE_ACCESSOR,
                        useExisting: EmployerPayGridComponent,
                        multi: true
                    }], changeDetection: ChangeDetectionStrategy.Default, template: "<div style=\"margin-left: -5px;\">\r\n    <div style=\"margin-left: 8px\"><b>+ Add</b> payments from your former employers</div>\r\n    <p-table #dt [rowHover]=\"true\" styleClass=\"p-datatable-striped app-datatable ion-padding-top\" [value]=\"employerPay\">\r\n        <ng-template pTemplate=\"header\" let-columns>\r\n            <tr class=\"ion-padding-top ion-padding-bottom\">\r\n                <th style=\"padding-left: 15px\">\r\n                    {{\"employer.pay.grid.header.employer\"|translate}}\r\n                </th>\r\n                <th>\r\n                    {{\"employer.pay.grid.header.payType\"|translate}}\r\n                </th>\r\n                <th></th>\r\n            </tr>\r\n        </ng-template>\r\n\r\n        <ng-template pTemplate=\"body\" let-employer let-rowIndex=\"rowIndex\">\r\n            <tr class=\"ion-padding-top ion-padding-bottom\">\r\n                <td style=\"padding-left: 15px\"><span class=\"p-column-title\">Employer</span><span>\r\n                        {{employer.employerName}}</span>\r\n                </td>\r\n                <td>\r\n                    <span class=\"p-column-title\">Pay Type</span>\r\n                    <ng-container *ngFor=\"let payType of employer.payTypes; let last=last\">\r\n                        <span *ngIf = \"payType.isChecked\">\r\n                            <tr>\r\n                                <td style=\"width: 275px; white-space: wrap;\">\r\n                                    {{payType.payType.text}}\r\n                                </td>\r\n                                <td>\r\n                                    <b>: {{payType.amount | currency}}</b>\r\n                                </td>\r\n                            </tr>\r\n                            <br *ngIf=\"!last\">\r\n                        </span>\r\n                    </ng-container>\r\n                </td>\r\n                <td style=\"text-align: center;\">\r\n                    <ion-button [id]=\"'btnEditEmployerPayment-' + rowIndex\" size=\"small\" color=\"success\" fill=\"outline\"\r\n                        (click)=\"editEmployerPayment(employer);\" class=\"action-button\"\r\n                        aria-label=\"Edit employer payment\">\r\n                        <fa-icon [icon]=\"['fal', 'edit']\" class=\"action-icon\"></fa-icon>\r\n                    </ion-button>\r\n\r\n                    <ion-button [id]=\"'btnDeleteEmployerPayment-' + rowIndex\" size=\"small\" color=\"success\"\r\n                        fill=\"outline\" (click)=\"deleteEmployerPayment(rowIndex);\" class=\"action-button\"\r\n                        aria-label=\"Remove employer payment\">\r\n                        <fa-icon [icon]=\"['fal', 'trash-alt']\" class=\"action-icon\"></fa-icon>\r\n                    </ion-button>\r\n                </td>\r\n            </tr>\r\n        </ng-template>\r\n\r\n        <ng-template pTemplate=\"summary\" let-columns>\r\n            <table *ngIf=\"!selected\">\r\n                <tr>\r\n                    <td [attr.colspan]=\"4\" style=\"width: 90%;\" class=\"ion-padding-top\">\r\n                        <div><b>+ Add</b> Payment</div>\r\n                    </td>\r\n                    <td class=\"ion-padding-top\">\r\n                        <ion-button id=\"addEmployerPaymentDetails\" aria-label=\"Add Payment Details\"\r\n                            (click)=\"addEmployerPay()\" fill=\"outline\" size=\"small\" class=\"action-button\">\r\n                            <fa-icon [icon]=\"['fal', 'plus']\" class=\"action-icon\"></fa-icon>\r\n                        </ion-button>\r\n                    </td>\r\n                </tr>\r\n            </table>\r\n        </ng-template>\r\n    </p-table>\r\n    <app-employer-pay (success)=\"addEmployerPayment($event)\" (onClose)=\"close()\" [empToEdit]=\"selectedEmployer\"\r\n        *ngIf=\"selected\">\r\n    </app-employer-pay>\r\n\r\n    <p-dialog [visible]=\"showDuplicatePopup\" [modal]=\"true\" appendTo=\"body\" position=\"top\"\r\n        [breakpoints]=\"{'1200px': '660px', '992px': '660px', '768px': '660px', '576px': '100vw'}\"\r\n        [style]=\"{width: '45vw'}\" [baseZIndex]=\"5000\" [draggable]=\"false\" [resizable]=\"false\" appendTo=\"body\"\r\n        closeOnEscape=\"false\">\r\n        <h4 class=\"heading\">Duplicate employer not allowed</h4>\r\n        <ion-label>It seems like you have added a employer that has been added already. Please check details and try\r\n            adding employer again.</ion-label>\r\n        <ng-template pTemplate=\"footer\">\r\n            <ion-button shape=\"round\" size=\"small\" type=\"submit\" fill=\"outline\" (click)=\"close()\">\r\n                Close\r\n            </ion-button>\r\n            <ion-button shape=\"round\" size=\"small\" type=\"submit\" fill=\"solid\" (click)=\"editDuplicateEmployer()\">\r\n                Edit\r\n            </ion-button>\r\n        </ng-template>\r\n    </p-dialog>\r\n\r\n</div>" }]
    }], () => [{ type: i1.LoggerService }, { type: i2.ValidationService }], { dynamicParam: [{
            type: Input
        }], modelDisplay: [{
            type: Output
        }] }); })();
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(EmployerPayGridComponent, { className: "EmployerPayGridComponent", filePath: "lib\\components\\employer-pay-grid\\employer-pay-grid.component.ts", lineNumber: 21 }); })();
//# sourceMappingURL=data:application/json;base64, 