import { __decorate } from "tslib";
import { Component, ViewChild, Inject } from '@angular/core';
import { MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ComponentLookup, CONFIRM_DIALOG_TYPE } from '../../@interfaces/eagna.interface';
import * as i0 from "@angular/core";
import * as i1 from "@angular/material/dialog";
import * as i2 from "@angular/common";
import * as i3 from "@angular/material/button";
import * as i4 from "@angular/material/datepicker";
import * as i5 from "@angular/material/form-field";
import * as i6 from "@angular/material/icon";
import * as i7 from "@angular/cdk/text-field";
import * as i8 from "@angular/material/input";
import * as i9 from "@angular/forms";
import * as i10 from "../circle-timer/circle-timer.component";
let ConfirmDialogComponent = class ConfirmDialogComponent {
    constructor(dialogRef, data) {
        this.dialogRef = dialogRef;
        this.data = data;
        this.newDate = null;
        this.timer = { output: null, start: null };
        this.types = CONFIRM_DIALOG_TYPE;
        this.noSetEmpty = false;
        this.title = data.title;
        if (typeof data.config == "string") {
            this.message = data.config;
            this.type = CONFIRM_DIALOG_TYPE.YES_NO;
        }
        else {
            this.message = data.config.message;
            this.titleIcon = data.config.titleIcon || null;
            this.iconClass = data.config.iconClass || null;
            this.type = data.config.type || CONFIRM_DIALOG_TYPE.YES_NO;
            this.customButtonOptions = data.config.customOptionButtons;
            if (data.config.timer) {
                this.timer.start = data.config.timer.value;
            }
            this.noSetEmpty = data.config.noSetEmpty || false;
            if (!!data.config.additionalForms) {
                this.additionalForms = data.config.additionalForms;
            }
        }
    }
    ngOnInit() {
    }
    resend() {
        if (typeof this.data.config != "string") {
            this.timer.start = this.data.config.timer.value;
            this.timer.output = this.timer.start;
            if (this.data.config.timer.resendFn) {
                this.data.config.timer.resendFn();
            }
        }
    }
    onConfirm(type, p) {
        let dataUponClose = { isConfirmed: true };
        if (type == CONFIRM_DIALOG_TYPE.DATE_PICKER) {
            dataUponClose.newDate = this.newDate;
        }
        else if (type == CONFIRM_DIALOG_TYPE.TOKEN) {
            dataUponClose.token = this.newValue;
        }
        else if (type == CONFIRM_DIALOG_TYPE.LARGE_TEXT) {
            dataUponClose.newValue = this.newValue;
        }
        else if (type == CONFIRM_DIALOG_TYPE.CUSTOM_OPTIONS) {
            dataUponClose.customOptionData = p.value;
        }
        if (!!this.additionalForms) {
            dataUponClose = { ...dataUponClose, ...{ additionalFormData: this.additionalForms.frmGrp.value } };
        }
        this.dialogRef.close(dataUponClose);
    }
    onDismiss() {
        this.dialogRef.close({ ...(this.additionalForms ? { additionalFormData: this.additionalForms.frmGrp.value } : {}), isConfirmed: false });
    }
};
ConfirmDialogComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: ConfirmDialogComponent, deps: [{ token: i1.MatDialogRef }, { token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component });
ConfirmDialogComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.0", type: ConfirmDialogComponent, selector: "eagna-confirm-dialog", viewQueries: [{ propertyName: "eagnaTimer", first: true, predicate: ["eagnaTimer"], descendants: true }], ngImport: i0, template: "<div class=\"eagna-modal\">\r\n    <div class=\"eagna-modal-header\">\r\n        <mat-icon *ngIf=\"titleIcon\" [class]=\"iconClass\">{{titleIcon}}</mat-icon>\r\n        <div class=\"eagna-modal-header-title\">{{title}}</div>\r\n        <div class=\"eagna-modal-close\">\r\n            <button mat-icon-button (click)=\"onDismiss()\" ><mat-icon>clear</mat-icon></button> <!-- mat-dialog-close -->\r\n        </div>\r\n    </div>\r\n    <mat-dialog-content class=\"mat-typography p-x-32\" [style.min-height]=\"!!additionalForms ? '200px' : ''\">\r\n        <div>\r\n            <p *ngIf=\"message\" class=\"pull-left full-width\" [innerHTML]=\"message\">  </p> <!-- [ngClass]=\"{'text-center':type == types.TOKEN}\" -->\r\n            <eagna-circle-timer #eagnaTimer *ngIf=\"type==types.TOKEN\" class=\"pull-right\" (timerOutput)=\"timer.output=$event\"\r\n                [timerStart]=\"timer.start\"></eagna-circle-timer> \r\n                \r\n        </div>\r\n        <ng-container [ngSwitch]=\"type\">\r\n            <ng-container *ngSwitchCase=\"types.DATE_PICKER\" [ngTemplateOutlet]=\"datePicker\"></ng-container>\r\n            <ng-container *ngSwitchCase=\"types.TOKEN\" [ngTemplateOutlet]=\"token\"></ng-container>\r\n            <ng-container *ngSwitchCase=\"types.LARGE_TEXT\" [ngTemplateOutlet]=\"largeText\"></ng-container>\r\n        </ng-container>\r\n        <ng-container *ngIf=\"!!additionalForms\" [ngTemplateOutlet]=\"additionalFormData\" [ngTemplateOutletContext]=\"{frm: additionalForms}\"></ng-container>\r\n    </mat-dialog-content>\r\n    <mat-dialog-actions align=\"end\">\r\n        <ng-container *ngIf=\"type==types.YES_NO\" [ngTemplateOutlet]=\"actionYesOrNo\"></ng-container>\r\n        <ng-container *ngIf=\"type==types.DATE_PICKER || type==types.TOKEN || type==types.LARGE_TEXT || type==types.GENERIC\"\r\n            [ngTemplateOutlet]=\"actionGeneric\" [ngTemplateOutletContext]=\"{isPristine: (type==types.DATE_PICKER && !newDate) || ((type==types.TOKEN || type==types.LARGE_TEXT) && !newValue)}\"></ng-container>\r\n        <ng-container *ngIf=\"type==types.CUSTOM_OPTIONS\" [ngTemplateOutlet]=\"actionCustomOptions\"></ng-container>\r\n    </mat-dialog-actions>\r\n</div>\r\n\r\n<ng-template #datePicker>\r\n    <mat-form-field>\r\n        <mat-label>Choose a date</mat-label>\r\n        <input matInput [matDatepicker]=\"picker\" [(ngModel)]=\"newDate\">\r\n        <!-- (dateInput)=\"addEvent('input', $event)\" (dateChange)=\"addEvent('change', $event)\" -->\r\n        <mat-datepicker-toggle matSuffix [for]=\"picker\"></mat-datepicker-toggle>\r\n        <mat-datepicker #picker></mat-datepicker>\r\n    </mat-form-field>\r\n</ng-template>\r\n<ng-template #token>\r\n    <mat-form-field>\r\n        <mat-label>Token</mat-label>\r\n        <mat-icon matPrefix color=\"'primary'\">monetization_on </mat-icon> &nbsp;\r\n        <input matInput [placeholder]=\"'Eagna.XX.XXXX'\" [(ngModel)]=\"newValue\">\r\n    </mat-form-field>\r\n</ng-template>\r\n<ng-template #largeText>\r\n    <mat-form-field>\r\n        <!-- <mat-label>New Value</mat-label> -->\r\n        <!-- placeholder=\"Comments...\" -->\r\n        <textarea matInput cdkTextareaAutosize #autosize=\"cdkTextareaAutosize\" cdkAutosizeMinRows=\"4\"\r\n            [(ngModel)]=\"newValue\"></textarea>\r\n    </mat-form-field>\r\n</ng-template>\r\n<ng-template #additionalFormData let-frm=\"frm\">\r\n    <!-- <eagna-form [frmGroup]=\"frm?.frmGrp\" [frmTemplate]=\"frm?.frmTpl\" [flexContent]=\"frm?.flexContent || false\"></eagna-form> -->\r\n</ng-template>\r\n<ng-template #actionYesOrNo>\r\n    <button mat-stroked-button class=\"b-danger font-danger\" (click)=\"onDismiss()\">No</button>\r\n    <button mat-button class=\"bg-success font-eagna-white\" (click)=\"onConfirm()\">Yes</button>\r\n</ng-template>\r\n<ng-template #actionGeneric let-isPristine=\"isPristine\">\r\n    <div class=\"pull-right\">\r\n        <button mat-stroked-button class=\"b-danger font-danger m-x-4\" (click)=\"onDismiss()\">Cancel</button>\r\n        <button mat-flat-button class=\"bg-success font-eagna-white m-x-4\" *ngIf=\"type==types.TOKEN && timer.output==0\"\r\n            (click)=\"resend();eagnaTimer.startTimer();\">Re-send email</button>\r\n\r\n        <button *ngIf=\"!noSetEmpty && isPristine\" mat-stroked-button class=\"b-eagna-accent m-x-4\"\r\n            (click)=\"newValue = null; onConfirm(type);\">\r\n            Set empty\r\n        </button>\r\n\r\n        <button mat-flat-button class=\"bg-success font-eagna-white m-x-4\" (click)=\"onConfirm(type)\"\r\n            [disabled]=\"isPristine || (!!additionalForms && additionalForms?.frmGrp?.invalid)\"\r\n            [class.cursor-not-allowed]=\"isPristine || (!!additionalForms && additionalForms?.frmGrp?.invalid)\">\r\n            {{type==types.DATE_PICKER || type==types.LARGE_TEXT ? 'Set' : (type==types.TOKEN ? 'Apply Token' : 'OK')}}\r\n        </button>\r\n    </div>\r\n</ng-template>\r\n<ng-template #actionCustomOptions>\r\n    <div class=\"pull-right\">\r\n        <!-- <button *ngIf=\"\" mat-stroked-button class=\"b-danger font-danger m-r-8\" (click)=\"onDismiss()\">Cancel</button> -->\r\n        <button *ngFor=\"let b of customButtonOptions\"\r\n            [color]=\"b.isButtonDefault ? 'primary' : (b.buttonColor || 'accent')\"\r\n            [class]=\"b.buttonClass\"\r\n            [ngClass]=\"{'mat-raised-button': b.isButtonDefault, 'btn': true}\" mat-flat-button\r\n            (click)=\"onConfirm(type, b)\">{{b.label}}</button> <!-- doBeforeClose(b) -->\r\n    </div>\r\n</ng-template>\r\n", styles: ["::ng-deep .mat-dialog-container{padding:24px!important}.eagna-flex-modal :host{display:flex;flex-direction:column}.eagna-flex-modal :host .header{display:flex!important;flex-direction:row!important}.eagna-flex-modal :host .header h2{flex:1!important}.eagna-flex-modal :host .mat-dialog-content{flex:1!important}\n"], dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i2.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i2.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "component", type: i3.MatButton, selector: "button[mat-button], button[mat-raised-button], button[mat-icon-button],             button[mat-fab], button[mat-mini-fab], button[mat-stroked-button],             button[mat-flat-button]", inputs: ["disabled", "disableRipple", "color"], exportAs: ["matButton"] }, { kind: "component", type: i4.MatDatepicker, selector: "mat-datepicker", exportAs: ["matDatepicker"] }, { kind: "directive", type: i4.MatDatepickerInput, selector: "input[matDatepicker]", inputs: ["matDatepicker", "min", "max", "matDatepickerFilter"], exportAs: ["matDatepickerInput"] }, { kind: "component", type: i4.MatDatepickerToggle, selector: "mat-datepicker-toggle", inputs: ["for", "tabIndex", "aria-label", "disabled", "disableRipple"], exportAs: ["matDatepickerToggle"] }, { kind: "directive", type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "directive", type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]" }, { kind: "component", type: i5.MatFormField, selector: "mat-form-field", inputs: ["color", "appearance", "hideRequiredMarker", "hintLabel", "floatLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i5.MatLabel, selector: "mat-label" }, { kind: "directive", type: i5.MatPrefix, selector: "[matPrefix]" }, { kind: "directive", type: i5.MatSuffix, selector: "[matSuffix]" }, { kind: "component", type: i6.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "directive", type: i7.CdkTextareaAutosize, selector: "textarea[cdkTextareaAutosize]", inputs: ["cdkAutosizeMinRows", "cdkAutosizeMaxRows", "cdkTextareaAutosize", "placeholder"], exportAs: ["cdkTextareaAutosize"] }, { kind: "directive", type: i8.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "directive", type: i9.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i9.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i9.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i10.CircleTimer, selector: "eagna-circle-timer", inputs: ["timerStart"], outputs: ["timerOutput"] }] });
ConfirmDialogComponent = __decorate([
    ComponentLookup("ConfirmDialogComponent")
], ConfirmDialogComponent);
export { ConfirmDialogComponent };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.0", ngImport: i0, type: ConfirmDialogComponent, decorators: [{
            type: Component,
            args: [{ selector: "eagna-confirm-dialog", template: "<div class=\"eagna-modal\">\r\n    <div class=\"eagna-modal-header\">\r\n        <mat-icon *ngIf=\"titleIcon\" [class]=\"iconClass\">{{titleIcon}}</mat-icon>\r\n        <div class=\"eagna-modal-header-title\">{{title}}</div>\r\n        <div class=\"eagna-modal-close\">\r\n            <button mat-icon-button (click)=\"onDismiss()\" ><mat-icon>clear</mat-icon></button> <!-- mat-dialog-close -->\r\n        </div>\r\n    </div>\r\n    <mat-dialog-content class=\"mat-typography p-x-32\" [style.min-height]=\"!!additionalForms ? '200px' : ''\">\r\n        <div>\r\n            <p *ngIf=\"message\" class=\"pull-left full-width\" [innerHTML]=\"message\">  </p> <!-- [ngClass]=\"{'text-center':type == types.TOKEN}\" -->\r\n            <eagna-circle-timer #eagnaTimer *ngIf=\"type==types.TOKEN\" class=\"pull-right\" (timerOutput)=\"timer.output=$event\"\r\n                [timerStart]=\"timer.start\"></eagna-circle-timer> \r\n                \r\n        </div>\r\n        <ng-container [ngSwitch]=\"type\">\r\n            <ng-container *ngSwitchCase=\"types.DATE_PICKER\" [ngTemplateOutlet]=\"datePicker\"></ng-container>\r\n            <ng-container *ngSwitchCase=\"types.TOKEN\" [ngTemplateOutlet]=\"token\"></ng-container>\r\n            <ng-container *ngSwitchCase=\"types.LARGE_TEXT\" [ngTemplateOutlet]=\"largeText\"></ng-container>\r\n        </ng-container>\r\n        <ng-container *ngIf=\"!!additionalForms\" [ngTemplateOutlet]=\"additionalFormData\" [ngTemplateOutletContext]=\"{frm: additionalForms}\"></ng-container>\r\n    </mat-dialog-content>\r\n    <mat-dialog-actions align=\"end\">\r\n        <ng-container *ngIf=\"type==types.YES_NO\" [ngTemplateOutlet]=\"actionYesOrNo\"></ng-container>\r\n        <ng-container *ngIf=\"type==types.DATE_PICKER || type==types.TOKEN || type==types.LARGE_TEXT || type==types.GENERIC\"\r\n            [ngTemplateOutlet]=\"actionGeneric\" [ngTemplateOutletContext]=\"{isPristine: (type==types.DATE_PICKER && !newDate) || ((type==types.TOKEN || type==types.LARGE_TEXT) && !newValue)}\"></ng-container>\r\n        <ng-container *ngIf=\"type==types.CUSTOM_OPTIONS\" [ngTemplateOutlet]=\"actionCustomOptions\"></ng-container>\r\n    </mat-dialog-actions>\r\n</div>\r\n\r\n<ng-template #datePicker>\r\n    <mat-form-field>\r\n        <mat-label>Choose a date</mat-label>\r\n        <input matInput [matDatepicker]=\"picker\" [(ngModel)]=\"newDate\">\r\n        <!-- (dateInput)=\"addEvent('input', $event)\" (dateChange)=\"addEvent('change', $event)\" -->\r\n        <mat-datepicker-toggle matSuffix [for]=\"picker\"></mat-datepicker-toggle>\r\n        <mat-datepicker #picker></mat-datepicker>\r\n    </mat-form-field>\r\n</ng-template>\r\n<ng-template #token>\r\n    <mat-form-field>\r\n        <mat-label>Token</mat-label>\r\n        <mat-icon matPrefix color=\"'primary'\">monetization_on </mat-icon> &nbsp;\r\n        <input matInput [placeholder]=\"'Eagna.XX.XXXX'\" [(ngModel)]=\"newValue\">\r\n    </mat-form-field>\r\n</ng-template>\r\n<ng-template #largeText>\r\n    <mat-form-field>\r\n        <!-- <mat-label>New Value</mat-label> -->\r\n        <!-- placeholder=\"Comments...\" -->\r\n        <textarea matInput cdkTextareaAutosize #autosize=\"cdkTextareaAutosize\" cdkAutosizeMinRows=\"4\"\r\n            [(ngModel)]=\"newValue\"></textarea>\r\n    </mat-form-field>\r\n</ng-template>\r\n<ng-template #additionalFormData let-frm=\"frm\">\r\n    <!-- <eagna-form [frmGroup]=\"frm?.frmGrp\" [frmTemplate]=\"frm?.frmTpl\" [flexContent]=\"frm?.flexContent || false\"></eagna-form> -->\r\n</ng-template>\r\n<ng-template #actionYesOrNo>\r\n    <button mat-stroked-button class=\"b-danger font-danger\" (click)=\"onDismiss()\">No</button>\r\n    <button mat-button class=\"bg-success font-eagna-white\" (click)=\"onConfirm()\">Yes</button>\r\n</ng-template>\r\n<ng-template #actionGeneric let-isPristine=\"isPristine\">\r\n    <div class=\"pull-right\">\r\n        <button mat-stroked-button class=\"b-danger font-danger m-x-4\" (click)=\"onDismiss()\">Cancel</button>\r\n        <button mat-flat-button class=\"bg-success font-eagna-white m-x-4\" *ngIf=\"type==types.TOKEN && timer.output==0\"\r\n            (click)=\"resend();eagnaTimer.startTimer();\">Re-send email</button>\r\n\r\n        <button *ngIf=\"!noSetEmpty && isPristine\" mat-stroked-button class=\"b-eagna-accent m-x-4\"\r\n            (click)=\"newValue = null; onConfirm(type);\">\r\n            Set empty\r\n        </button>\r\n\r\n        <button mat-flat-button class=\"bg-success font-eagna-white m-x-4\" (click)=\"onConfirm(type)\"\r\n            [disabled]=\"isPristine || (!!additionalForms && additionalForms?.frmGrp?.invalid)\"\r\n            [class.cursor-not-allowed]=\"isPristine || (!!additionalForms && additionalForms?.frmGrp?.invalid)\">\r\n            {{type==types.DATE_PICKER || type==types.LARGE_TEXT ? 'Set' : (type==types.TOKEN ? 'Apply Token' : 'OK')}}\r\n        </button>\r\n    </div>\r\n</ng-template>\r\n<ng-template #actionCustomOptions>\r\n    <div class=\"pull-right\">\r\n        <!-- <button *ngIf=\"\" mat-stroked-button class=\"b-danger font-danger m-r-8\" (click)=\"onDismiss()\">Cancel</button> -->\r\n        <button *ngFor=\"let b of customButtonOptions\"\r\n            [color]=\"b.isButtonDefault ? 'primary' : (b.buttonColor || 'accent')\"\r\n            [class]=\"b.buttonClass\"\r\n            [ngClass]=\"{'mat-raised-button': b.isButtonDefault, 'btn': true}\" mat-flat-button\r\n            (click)=\"onConfirm(type, b)\">{{b.label}}</button> <!-- doBeforeClose(b) -->\r\n    </div>\r\n</ng-template>\r\n", styles: ["::ng-deep .mat-dialog-container{padding:24px!important}.eagna-flex-modal :host{display:flex;flex-direction:column}.eagna-flex-modal :host .header{display:flex!important;flex-direction:row!important}.eagna-flex-modal :host .header h2{flex:1!important}.eagna-flex-modal :host .mat-dialog-content{flex:1!important}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.MatDialogRef }, { type: ConfirmDialogModel, decorators: [{
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }]; }, propDecorators: { eagnaTimer: [{
                type: ViewChild,
                args: ["eagnaTimer"]
            }] } });
export class ConfirmDialogModel {
    constructor(title, config) {
        this.title = title;
        this.config = config;
        if (!config) {
            this.config = { message: '' };
        }
    }
}
//# sourceMappingURL=data:application/json;base64, 