import { CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { Inject, Component, inject, Injectable } from '@angular/core';
import { FormsModule } from '@angular/forms';
import * as i1 from '@angular/material/dialog';
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
import * as i2 from '@angular/material/icon';
import { MatIconModule } from '@angular/material/icon';
import { SdButton } from '@sdcorejs/angular/components/button';
import { SdDate } from '@sdcorejs/angular/forms/date';
import { SdRadio } from '@sdcorejs/angular/forms/radio';
import { SdTextarea } from '@sdcorejs/angular/forms/textarea';
import * as uuid from 'uuid';
import { I18nService } from '@sdcorejs/angular/i18n';

class DialogConfirmComponent {
    dialogRef;
    data;
    value;
    required = false;
    id = `I${uuid.v4()}`;
    constructor(dialogRef, data) {
        this.dialogRef = dialogRef;
        this.data = data;
        if (data?.input) {
            this.value = data?.input?.defaultValue ?? '';
            this.required = data?.input?.required || false;
        }
        if (data?.date) {
            this.value = data?.date?.defaultValue ?? '';
            this.required = data?.date?.required || false;
        }
        if (data?.radio) {
            this.value = data?.radio?.defaultValue ?? '';
            this.required = data?.radio?.required || false;
        }
    }
    onCancel = () => {
        this.dialogRef.close({ action: 'CANCEL', value: null });
    };
    onAccept = () => {
        // Always return an object with action and value for consistency
        if (this.data?.radio || this.data?.input || this.data?.date) {
            this.dialogRef.close({ action: 'ACCEPT', value: this.value });
        }
        else {
            this.dialogRef.close({ action: 'ACCEPT', value: null });
        }
    };
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: DialogConfirmComponent, deps: [{ token: i1.MatDialogRef }, { token: MAT_DIALOG_DATA }], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.17", type: DialogConfirmComponent, isStandalone: true, selector: "sd-dialog-confirm", ngImport: i0, template: "<div mat-dialog-title class=\"\">\n  @if (data.icon) {\n    <mat-icon>\n      {{ data.icon }}\n    </mat-icon>\n  }\n  <span class=\"T24M\" [innerHtml]=\"data.title || 'Confirm'\"></span>\n</div>\n<div mat-dialog-content>\n  <div class=\"T14R mb-4\" [innerHtml]=\"data.message\"></div>\n  @if (data.input) {\n    <sd-textarea [placeholder]=\"data.input.placeholder\" [(model)]=\"value\" [rows]=\"5\" [maxlength]=\"data.input.maxlength!\" />\n  }\n  @if (data.date) {\n    <sd-date\n      [placeholder]=\"data.date.placeholder\"\n      [(model)]=\"value\"\n      type=\"date\"\n      [min]=\"data.date.min!\"\n      [max]=\"data.date.max!\"\n      [required]=\"data.date.required\">\n    </sd-date>\n  }\n  @if (data.radio) {\n    <sd-radio\n      [items]=\"data.radio.items\"\n      [valueField]=\"data.radio.valueField\"\n      [displayField]=\"data.radio.displayField\"\n      [display]=\"data.radio.display || 'column'\"\n      [(model)]=\"value\"\n      [required]=\"data.radio.required\">\n    </sd-radio>\n  }\n</div>\n<div mat-dialog-actions align=\"end\">\n  @if (data.noTitle) {\n    <sd-button [color]=\"data.noButtonColor || 'secondary'\" [title]=\"data.noTitle\" (click)=\"onCancel()\"></sd-button>\n  }\n  @if (data.yesTitle) {\n    <sd-button\n      class=\"ml-8\"\n      type=\"fill\"\n      [color]=\"data.yesButtonColor || 'primary'\"\n      [disabled]=\"required && !value\"\n      cdkFocusInitial\n      [title]=\"data.yesTitle\"\n      (click)=\"onAccept()\"></sd-button>\n  }\n</div>\n", styles: [".text-primary{color:var(--sd-primary)!important}.bg-primary{background:var(--sd-primary)!important}.border-primary{border-color:var(--sd-primary)!important}.text-primary-light{color:var(--sd-primary-light)!important}.bg-primary-light{background:var(--sd-primary-light)!important}.border-primary-light{border-color:var(--sd-primary-light)!important}.text-primary-dark{color:var(--sd-primary-dark)!important}.bg-primary-dark{background:var(--sd-primary-dark)!important}.border-primary-dark{border-color:var(--sd-primary-dark)!important}.text-info{color:var(--sd-info)!important}.bg-info{background:var(--sd-info)!important}.border-info{border-color:var(--sd-info)!important}.text-info-light{color:var(--sd-info-light)!important}.bg-info-light{background:var(--sd-info-light)!important}.border-info-light{border-color:var(--sd-info-light)!important}.text-info-dark{color:var(--sd-info-dark)!important}.bg-info-dark{background:var(--sd-info-dark)!important}.border-info-dark{border-color:var(--sd-info-dark)!important}.text-success{color:var(--sd-success)!important}.bg-success{background:var(--sd-success)!important}.border-success{border-color:var(--sd-success)!important}.text-success-light{color:var(--sd-success-light)!important}.bg-success-light{background:var(--sd-success-light)!important}.border-success-light{border-color:var(--sd-success-light)!important}.text-success-dark{color:var(--sd-success-dark)!important}.bg-success-dark{background:var(--sd-success-dark)!important}.border-success-dark{border-color:var(--sd-success-dark)!important}.text-warning{color:var(--sd-warning)!important}.bg-warning{background:var(--sd-warning)!important}.border-warning{border-color:var(--sd-warning)!important}.text-warning-light{color:var(--sd-warning-light)!important}.bg-warning-light{background:var(--sd-warning-light)!important}.border-warning-light{border-color:var(--sd-warning-light)!important}.text-warning-dark{color:var(--sd-warning-dark)!important}.bg-warning-dark{background:var(--sd-warning-dark)!important}.border-warning-dark{border-color:var(--sd-warning-dark)!important}.text-error{color:var(--sd-error)!important}.bg-error{background:var(--sd-error)!important}.border-error{border-color:var(--sd-error)!important}.text-error-light{color:var(--sd-error-light)!important}.bg-error-light{background:var(--sd-error-light)!important}.border-error-light{border-color:var(--sd-error-light)!important}.text-error-dark{color:var(--sd-error-dark)!important}.bg-error-dark{background:var(--sd-error-dark)!important}.border-error-dark{border-color:var(--sd-error-dark)!important}.text-secondary{color:var(--sd-secondary)!important}.bg-secondary{background:var(--sd-secondary)!important}.border-secondary{border-color:var(--sd-secondary)!important}.text-secondary-light{color:var(--sd-secondary-light)!important}.bg-secondary-light{background:var(--sd-secondary-light)!important}.border-secondary-light{border-color:var(--sd-secondary-light)!important}.text-secondary-dark{color:var(--sd-secondary-dark)!important}.bg-secondary-dark{background:var(--sd-secondary-dark)!important}.border-secondary-dark{border-color:var(--sd-secondary-dark)!important}.text-light{color:var(--sd-light)!important}.bg-light{background:var(--sd-light)!important}.border-light{border-color:var(--sd-light)!important}.text-dark{color:var(--sd-dark)!important}.bg-dark{background:var(--sd-dark)!important}.border-dark{border-color:var(--sd-dark)!important}.text-black500{color:var(--sd-black500)!important}.bg-black500{background:var(--sd-black500)!important}.border-black500{border-color:var(--sd-black500)!important}.text-black400{color:var(--sd-black400)!important}.bg-black400{background:var(--sd-black400)!important}.border-black400{border-color:var(--sd-black400)!important}.text-black300{color:var(--sd-black300)!important}.bg-black300{background:var(--sd-black300)!important}.border-black300{border-color:var(--sd-black300)!important}.text-black200{color:var(--sd-black200)!important}.bg-black200{background:var(--sd-black200)!important}.border-black200{border-color:var(--sd-black200)!important}.text-black100{color:var(--sd-black100)!important}.bg-black100{background:var(--sd-black100)!important}.border-black100{border-color:var(--sd-black100)!important}.text-white{color:#fff!important}.bg-white{background:#fff!important}.border-white{border-color:#fff!important}.text-black{color:#000!important}.bg-black{background:#000!important}.border-black{border-color:#000!important}:host .mat-dialog-content{margin:0 -16px 16px!important}:host .mat-button{background-color:#f5f5f5}:host ::ng-deep .mat-dialog-title{display:flex;align-items:center;justify-content:flex-start}:host ::ng-deep .mat-dialog-title .mat-icon{margin-right:5px}:host{display:block}:host ::ng-deep .mat-dialog-title .mat-icon.info{color:var(--sd-info)}:host ::ng-deep .mat-dialog-title .mat-icon.warning{color:var(--sd-warning)}:host ::ng-deep .mat-dialog-title .mat-icon.success{color:var(--sd-success)}:host ::ng-deep .mat-dialog-title .mat-icon.error{color:var(--sd-error)}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "ngmodule", type: FormsModule }, { kind: "ngmodule", type: MatDialogModule }, { kind: "directive", type: i1.MatDialogTitle, selector: "[mat-dialog-title], [matDialogTitle]", inputs: ["id"], exportAs: ["matDialogTitle"] }, { kind: "directive", type: i1.MatDialogActions, selector: "[mat-dialog-actions], mat-dialog-actions, [matDialogActions]", inputs: ["align"] }, { kind: "directive", type: i1.MatDialogContent, selector: "[mat-dialog-content], mat-dialog-content, [matDialogContent]" }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i2.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: SdButton, selector: "sd-button", inputs: ["autoId", "type", "color", "size", "fontSet", "title", "width", "tooltip", "prefixIcon", "suffixIcon", "disabled", "loading", "block", "htmlType"], outputs: ["click"] }, { kind: "component", type: SdDate, selector: "sd-date", inputs: ["autoId", "name", "size", "form", "label", "helperText", "placeholder", "hideInlineError", "required", "disabled", "viewed", "clearable", "inlineError", "hyperlink", "appearance", "floatLabel", "min", "minDate", "max", "maxDate", "model"], outputs: ["modelChange", "sdChange", "sdFocus"] }, { kind: "component", type: SdRadio, selector: "sd-radio", inputs: ["autoId", "name", "form", "label", "placeholder", "display", "items", "valueField", "displayField", "required", "inlineError", "disabled", "viewed", "color", "hyperlink", "model"], outputs: ["modelChange", "sdChange", "sdSelection"] }, { kind: "component", type: SdTextarea, selector: "sd-textarea", inputs: ["autoId", "name", "size", "form", "label", "helperText", "placeholder", "rows", "hideInlineError", "required", "disabled", "viewed", "autoHeight", "maxlength", "pattern", "validator", "inlineError", "appearance", "floatLabel", "model"], outputs: ["modelChange", "sdChange"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: DialogConfirmComponent, decorators: [{
            type: Component,
            args: [{ selector: 'sd-dialog-confirm', imports: [CommonModule, FormsModule, MatDialogModule, MatIconModule, SdButton, SdDate, SdRadio, SdTextarea], template: "<div mat-dialog-title class=\"\">\n  @if (data.icon) {\n    <mat-icon>\n      {{ data.icon }}\n    </mat-icon>\n  }\n  <span class=\"T24M\" [innerHtml]=\"data.title || 'Confirm'\"></span>\n</div>\n<div mat-dialog-content>\n  <div class=\"T14R mb-4\" [innerHtml]=\"data.message\"></div>\n  @if (data.input) {\n    <sd-textarea [placeholder]=\"data.input.placeholder\" [(model)]=\"value\" [rows]=\"5\" [maxlength]=\"data.input.maxlength!\" />\n  }\n  @if (data.date) {\n    <sd-date\n      [placeholder]=\"data.date.placeholder\"\n      [(model)]=\"value\"\n      type=\"date\"\n      [min]=\"data.date.min!\"\n      [max]=\"data.date.max!\"\n      [required]=\"data.date.required\">\n    </sd-date>\n  }\n  @if (data.radio) {\n    <sd-radio\n      [items]=\"data.radio.items\"\n      [valueField]=\"data.radio.valueField\"\n      [displayField]=\"data.radio.displayField\"\n      [display]=\"data.radio.display || 'column'\"\n      [(model)]=\"value\"\n      [required]=\"data.radio.required\">\n    </sd-radio>\n  }\n</div>\n<div mat-dialog-actions align=\"end\">\n  @if (data.noTitle) {\n    <sd-button [color]=\"data.noButtonColor || 'secondary'\" [title]=\"data.noTitle\" (click)=\"onCancel()\"></sd-button>\n  }\n  @if (data.yesTitle) {\n    <sd-button\n      class=\"ml-8\"\n      type=\"fill\"\n      [color]=\"data.yesButtonColor || 'primary'\"\n      [disabled]=\"required && !value\"\n      cdkFocusInitial\n      [title]=\"data.yesTitle\"\n      (click)=\"onAccept()\"></sd-button>\n  }\n</div>\n", styles: [".text-primary{color:var(--sd-primary)!important}.bg-primary{background:var(--sd-primary)!important}.border-primary{border-color:var(--sd-primary)!important}.text-primary-light{color:var(--sd-primary-light)!important}.bg-primary-light{background:var(--sd-primary-light)!important}.border-primary-light{border-color:var(--sd-primary-light)!important}.text-primary-dark{color:var(--sd-primary-dark)!important}.bg-primary-dark{background:var(--sd-primary-dark)!important}.border-primary-dark{border-color:var(--sd-primary-dark)!important}.text-info{color:var(--sd-info)!important}.bg-info{background:var(--sd-info)!important}.border-info{border-color:var(--sd-info)!important}.text-info-light{color:var(--sd-info-light)!important}.bg-info-light{background:var(--sd-info-light)!important}.border-info-light{border-color:var(--sd-info-light)!important}.text-info-dark{color:var(--sd-info-dark)!important}.bg-info-dark{background:var(--sd-info-dark)!important}.border-info-dark{border-color:var(--sd-info-dark)!important}.text-success{color:var(--sd-success)!important}.bg-success{background:var(--sd-success)!important}.border-success{border-color:var(--sd-success)!important}.text-success-light{color:var(--sd-success-light)!important}.bg-success-light{background:var(--sd-success-light)!important}.border-success-light{border-color:var(--sd-success-light)!important}.text-success-dark{color:var(--sd-success-dark)!important}.bg-success-dark{background:var(--sd-success-dark)!important}.border-success-dark{border-color:var(--sd-success-dark)!important}.text-warning{color:var(--sd-warning)!important}.bg-warning{background:var(--sd-warning)!important}.border-warning{border-color:var(--sd-warning)!important}.text-warning-light{color:var(--sd-warning-light)!important}.bg-warning-light{background:var(--sd-warning-light)!important}.border-warning-light{border-color:var(--sd-warning-light)!important}.text-warning-dark{color:var(--sd-warning-dark)!important}.bg-warning-dark{background:var(--sd-warning-dark)!important}.border-warning-dark{border-color:var(--sd-warning-dark)!important}.text-error{color:var(--sd-error)!important}.bg-error{background:var(--sd-error)!important}.border-error{border-color:var(--sd-error)!important}.text-error-light{color:var(--sd-error-light)!important}.bg-error-light{background:var(--sd-error-light)!important}.border-error-light{border-color:var(--sd-error-light)!important}.text-error-dark{color:var(--sd-error-dark)!important}.bg-error-dark{background:var(--sd-error-dark)!important}.border-error-dark{border-color:var(--sd-error-dark)!important}.text-secondary{color:var(--sd-secondary)!important}.bg-secondary{background:var(--sd-secondary)!important}.border-secondary{border-color:var(--sd-secondary)!important}.text-secondary-light{color:var(--sd-secondary-light)!important}.bg-secondary-light{background:var(--sd-secondary-light)!important}.border-secondary-light{border-color:var(--sd-secondary-light)!important}.text-secondary-dark{color:var(--sd-secondary-dark)!important}.bg-secondary-dark{background:var(--sd-secondary-dark)!important}.border-secondary-dark{border-color:var(--sd-secondary-dark)!important}.text-light{color:var(--sd-light)!important}.bg-light{background:var(--sd-light)!important}.border-light{border-color:var(--sd-light)!important}.text-dark{color:var(--sd-dark)!important}.bg-dark{background:var(--sd-dark)!important}.border-dark{border-color:var(--sd-dark)!important}.text-black500{color:var(--sd-black500)!important}.bg-black500{background:var(--sd-black500)!important}.border-black500{border-color:var(--sd-black500)!important}.text-black400{color:var(--sd-black400)!important}.bg-black400{background:var(--sd-black400)!important}.border-black400{border-color:var(--sd-black400)!important}.text-black300{color:var(--sd-black300)!important}.bg-black300{background:var(--sd-black300)!important}.border-black300{border-color:var(--sd-black300)!important}.text-black200{color:var(--sd-black200)!important}.bg-black200{background:var(--sd-black200)!important}.border-black200{border-color:var(--sd-black200)!important}.text-black100{color:var(--sd-black100)!important}.bg-black100{background:var(--sd-black100)!important}.border-black100{border-color:var(--sd-black100)!important}.text-white{color:#fff!important}.bg-white{background:#fff!important}.border-white{border-color:#fff!important}.text-black{color:#000!important}.bg-black{background:#000!important}.border-black{border-color:#000!important}:host .mat-dialog-content{margin:0 -16px 16px!important}:host .mat-button{background-color:#f5f5f5}:host ::ng-deep .mat-dialog-title{display:flex;align-items:center;justify-content:flex-start}:host ::ng-deep .mat-dialog-title .mat-icon{margin-right:5px}:host{display:block}:host ::ng-deep .mat-dialog-title .mat-icon.info{color:var(--sd-info)}:host ::ng-deep .mat-dialog-title .mat-icon.warning{color:var(--sd-warning)}:host ::ng-deep .mat-dialog-title .mat-icon.success{color:var(--sd-success)}:host ::ng-deep .mat-dialog-title .mat-icon.error{color:var(--sd-error)}\n"] }]
        }], ctorParameters: () => [{ type: i1.MatDialogRef }, { type: undefined, decorators: [{
                    type: Inject,
                    args: [MAT_DIALOG_DATA]
                }] }] });

class SdConfirmService {
    dialog;
    #i18n = inject(I18nService);
    constructor(dialog) {
        this.dialog = dialog;
    }
    confirm = (message, option = {}) => {
        const dialogRef = this.dialog.open(DialogConfirmComponent, {
            width: option?.width || '400px',
            disableClose: option?.disableBackdropClose ?? true,
            data: {
                title: option?.title || this.#i18n.t('core.confirm.title'),
                message,
                yesTitle: option?.yesTitle || this.#i18n.t('core.confirm.yes'),
                noTitle: option?.noTitle || this.#i18n.t('core.confirm.no'),
                noButtonColor: option?.noButtonColor || 'secondary',
                yesButtonColor: option?.yesButtonColor || 'primary',
            },
        });
        return new Promise((resolve, reject) => {
            dialogRef.afterClosed().subscribe(result => {
                if (result) {
                    if (result.action === 'CANCEL') {
                        reject(result.action);
                    }
                    else if (result.action === 'ACCEPT') {
                        resolve(result.value);
                    }
                }
            });
        });
    };
    withInput = (message, option) => {
        const dialogRef = this.dialog.open(DialogConfirmComponent, {
            width: '400px',
            disableClose: option?.disableBackdropClose ?? true,
            data: {
                title: option?.title || this.#i18n.t('core.confirm.title'),
                message,
                yesTitle: option?.yesTitle || this.#i18n.t('core.confirm.yes-short'),
                noTitle: option?.noTitle || this.#i18n.t('core.confirm.no-short'),
                noButtonColor: option?.noButtonColor || 'secondary',
                yesButtonColor: option?.yesButtonColor || 'primary',
                input: {
                    maxlength: option?.maxlength || 255,
                    required: option?.required,
                    defaultValue: option?.defaultValue || '',
                },
            },
        });
        return new Promise((resolve, reject) => {
            dialogRef.afterClosed().subscribe(result => {
                if (result) {
                    if (result.action === 'CANCEL') {
                        reject(result.action);
                    }
                    else if (result.action === 'ACCEPT') {
                        resolve(result.value);
                    }
                }
            });
        });
    };
    withRadio = (message, option) => {
        const dialogRef = this.dialog.open(DialogConfirmComponent, {
            width: '400px',
            disableClose: option?.disableBackdropClose ?? true,
            data: {
                title: option?.title || this.#i18n.t('core.confirm.title'),
                message,
                yesTitle: option?.yesTitle || this.#i18n.t('core.confirm.yes-short'),
                noTitle: option?.noTitle || this.#i18n.t('core.confirm.no-short'),
                noButtonColor: option?.noButtonColor || 'secondary',
                yesButtonColor: option?.yesButtonColor || 'primary',
                radio: {
                    items: option?.items || [],
                    valueField: option?.valueField || 'value',
                    displayField: option?.displayField || 'label',
                    display: option?.display || 'row',
                    required: option?.required,
                    defaultValue: option?.defaultValue,
                },
            },
        });
        return new Promise((resolve, reject) => {
            dialogRef.afterClosed().subscribe(result => {
                if (result) {
                    if (result.action === 'CANCEL') {
                        reject(result.action);
                    }
                    else if (result.action === 'ACCEPT') {
                        resolve(result.value);
                    }
                }
            });
        });
    };
    withDate = (message, option) => {
        const dialogRef = this.dialog.open(DialogConfirmComponent, {
            width: '400px',
            disableClose: option?.disableBackdropClose ?? true,
            data: {
                title: option?.title || this.#i18n.t('core.confirm.title'),
                message,
                yesTitle: option?.yesTitle || this.#i18n.t('core.confirm.yes-short'),
                noTitle: option?.noTitle || this.#i18n.t('core.confirm.no-short'),
                noButtonColor: option?.noButtonColor || 'secondary',
                yesButtonColor: option?.yesButtonColor || 'primary',
                date: {
                    placeholder: option?.placeholder,
                    required: option?.required,
                    defaultValue: option?.defaultValue || '',
                },
            },
        });
        return new Promise((resolve, reject) => {
            dialogRef.afterClosed().subscribe(result => {
                if (result) {
                    if (result.action === 'CANCEL') {
                        reject(result.action);
                    }
                    else if (result.action === 'ACCEPT') {
                        resolve(result.value);
                    }
                }
            });
        });
    };
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdConfirmService, deps: [{ token: i1.MatDialog }], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdConfirmService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.17", ngImport: i0, type: SdConfirmService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }], ctorParameters: () => [{ type: i1.MatDialog }] });

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

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

export { DialogConfirmComponent, SdConfirmService };
//# sourceMappingURL=sdcorejs-angular-services-confirm.mjs.map
