import { Component, Inject, Injectable, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog, MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { FormsModule } from '@angular/forms';
import { SdButtonModule } from '@sd-angular/core/button';
import { v4 } from 'uuid';
import { SdDateTimeModule } from '@sd-angular/core/date-time';
import '@sd-angular/core/common';

class DialogConfirmComponent {
    constructor(dialogRef, data) {
        var _a, _b, _c, _d, _e, _f, _g;
        this.dialogRef = dialogRef;
        this.data = data;
        this.required = false;
        this.isString = false;
        this.id = `I${v4()}`;
        this.isString = typeof ((_a = this.data) === null || _a === void 0 ? void 0 : _a.message) === 'string';
        if (data === null || data === void 0 ? void 0 : data.input) {
            this.value = (_c = (_b = data === null || data === void 0 ? void 0 : data.input) === null || _b === void 0 ? void 0 : _b.defaultValue) !== null && _c !== void 0 ? _c : '';
            this.required = ((_d = data === null || data === void 0 ? void 0 : data.input) === null || _d === void 0 ? void 0 : _d.required) || false;
        }
        if (data === null || data === void 0 ? void 0 : data.date) {
            this.value = (_f = (_e = data === null || data === void 0 ? void 0 : data.date) === null || _e === void 0 ? void 0 : _e.defaultValue) !== null && _f !== void 0 ? _f : '';
            this.required = ((_g = data === null || data === void 0 ? void 0 : data.date) === null || _g === void 0 ? void 0 : _g.required) || false;
        }
    }
}
DialogConfirmComponent.decorators = [
    { type: Component, args: [{
                selector: 'sd-dialog-confirm',
                template: "<h1 mat-dialog-title class=\"\">\r\n  <mat-icon *ngIf=\"data?.icon\" [ngClass]=\"data?.icon\">\r\n    {{ data?.icon }}\r\n  </mat-icon>\r\n  <span [innerHtml]=\"data?.title || 'Confirm'\"></span>\r\n</h1>\r\n<div mat-dialog-content>\r\n  <div *ngIf=\"isString\" [innerHtml]=\"data?.message\"></div>\r\n  <div *ngIf=\"!isString\" [innerHtml]=\"data?.message | json\"></div>\r\n  <div *ngIf=\"data?.input\">\r\n    <mat-form-field appearance=\"outline\">\r\n      <textarea style=\"width: 100%\" matInput [placeholder]=\"data.input?.placeholder\" [(ngModel)]=\"value\"\r\n        autocomplete=\"off\" rows=\"5\" [maxlength]=\"data.input?.maxlength\"></textarea>\r\n    </mat-form-field>\r\n  </div>\r\n  <div *ngIf=\"data?.date\">\r\n    <sd-date-time [placeholder]=\"data.date?.placeholder\" [(model)]=\"value\" type=\"date\" [min]=\"data.date?.min\"\r\n      [max]=\"data.date?.max\" [required]=\"required\">\r\n    </sd-date-time>\r\n  </div>\r\n</div>\r\n<div mat-dialog-actions align=\"end\">\r\n  <sd-button *ngIf=\"data?.noTitle\" [color]=\"data?.noButtonColor || 'secondary'\" [mat-dialog-close]=\"'CANCEL'\"\r\n    [title]=\"data?.noTitle\" size=\"sm\"></sd-button>\r\n  <sd-button class=\"ml-12\" *ngIf=\"data?.yesTitle\" [mat-dialog-close]=\"value || 'ACCEPT'\"\r\n    [color]=\"data?.yesButtonColor || 'primary'\" [disabled]=\"required && !value\" cdkFocusInitial\r\n    [title]=\"data?.yesTitle\" size=\"sm\"></sd-button>\r\n</div>",
                styles: [":host .mat-dialog-content{margin:0 -16px 16px!important}:host .mat-button{background-color:#f5f5f5}:host>>>.mat-dialog-title{align-items:center;display:flex;justify-content:flex-start}:host>>>.mat-dialog-title .mat-icon{margin-right:5px}:host{display:block;padding:12px 16px}:host>>>.mat-dialog-title .mat-icon.info{color:#2962ff}:host>>>.mat-dialog-title .mat-icon.warning{color:#ffc107}:host>>>.mat-dialog-title .mat-icon.done{color:#4caf50}:host>>>.mat-dialog-title .mat-icon.error{color:#d32f2f}"]
            },] }
];
DialogConfirmComponent.ctorParameters = () => [
    { type: MatDialogRef },
    { type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] }
];

class SdConfirmService {
    constructor(dialog) {
        this.dialog = dialog;
        this.withInput = (option) => {
            const dialogRef = this.dialog.open(DialogConfirmComponent, {
                width: '400px',
                data: {
                    title: (option === null || option === void 0 ? void 0 : option.title) || 'Xác nhận',
                    message: option === null || option === void 0 ? void 0 : option.message,
                    yesTitle: (option === null || option === void 0 ? void 0 : option.yesTitle) || 'Có',
                    noTitle: (option === null || option === void 0 ? void 0 : option.noTitle) || 'Không',
                    noButtonColor: (option === null || option === void 0 ? void 0 : option.noButtonColor) || 'secondary',
                    yesButtonColor: (option === null || option === void 0 ? void 0 : option.yesButtonColor) || 'primary',
                    input: {
                        maxlength: (option === null || option === void 0 ? void 0 : option.maxlength) || 255,
                        required: option === null || option === void 0 ? void 0 : option.required,
                        defaultValue: (option === null || option === void 0 ? void 0 : option.defaultValue) || ''
                    },
                },
            });
            return new Promise((resolve, reject) => {
                dialogRef.afterClosed().subscribe((result) => {
                    if (result) {
                        if (result === 'ACCEPT') {
                            resolve(result);
                        }
                        else if (result === 'CANCEL') {
                            reject(result);
                        }
                        else {
                            resolve(result);
                        }
                    }
                });
            });
        };
        this.withDate = (option) => {
            const dialogRef = this.dialog.open(DialogConfirmComponent, {
                width: '400px',
                data: {
                    title: (option === null || option === void 0 ? void 0 : option.title) || 'Xác nhận',
                    message: option === null || option === void 0 ? void 0 : option.message,
                    yesTitle: (option === null || option === void 0 ? void 0 : option.yesTitle) || 'Có',
                    noTitle: (option === null || option === void 0 ? void 0 : option.noTitle) || 'Không',
                    noButtonColor: (option === null || option === void 0 ? void 0 : option.noButtonColor) || 'secondary',
                    yesButtonColor: (option === null || option === void 0 ? void 0 : option.yesButtonColor) || 'primary',
                    date: {
                        placeholder: option === null || option === void 0 ? void 0 : option.placeholder,
                        required: option === null || option === void 0 ? void 0 : option.required,
                        defaultValue: (option === null || option === void 0 ? void 0 : option.defaultValue) || '',
                    },
                },
            });
            return new Promise((resolve, reject) => {
                dialogRef.afterClosed().subscribe((result) => {
                    if (result) {
                        if (result === 'ACCEPT') {
                            resolve(result);
                        }
                        else if (result === 'CANCEL') {
                            reject(result);
                        }
                        else {
                            resolve(result);
                        }
                    }
                });
            });
        };
    }
}
SdConfirmService.decorators = [
    { type: Injectable }
];
SdConfirmService.ctorParameters = () => [
    { type: MatDialog }
];

class SdConfirmModule {
}
SdConfirmModule.decorators = [
    { type: NgModule, args: [{
                imports: [
                    CommonModule,
                    FormsModule,
                    MatFormFieldModule,
                    MatInputModule,
                    SdDateTimeModule,
                    MatIconModule,
                    MatButtonModule,
                    MatDialogModule,
                    SdButtonModule,
                ],
                declarations: [DialogConfirmComponent],
                entryComponents: [DialogConfirmComponent],
                exports: [],
                providers: [SdConfirmService],
            },] }
];

/*
 * Public API Surface of superdev-angular-core
 */

/**
 * Generated bundle index. Do not edit.
 */

export { DialogConfirmComponent, SdConfirmModule, SdConfirmService };
//# sourceMappingURL=sd-angular-core-confirm.js.map
