import * as i0 from '@angular/core';
import { inject, signal, Injectable, Component } from '@angular/core';
import { ConfirmationService as ConfirmationService$1 } from 'primeng/api';
import { TranslocoService } from '@jsverse/transloco';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import { ConfirmDialog } from 'primeng/confirmdialog';
import { Button } from '@masterteam/components/button';
import { Icon } from '@masterteam/icons';
import { ConfirmPopup } from 'primeng/confirmpopup';

class ConfirmationService {
    confirmationService = inject(ConfirmationService$1);
    transloco = inject(TranslocoService);
    defaultConfig = {
        header: this.transloco.translate('components.confirmation.header'),
        message: this.transloco.translate('components.confirmation.message'),
        icon: 'alert.alert-triangle',
        acceptLabel: this.transloco.translate('components.confirmation.yes'),
        rejectLabel: this.transloco.translate('components.confirmation.cancel'),
        acceptButton: {
            severity: 'primary',
            variant: undefined,
        },
        rejectButton: {
            severity: 'secondary',
            variant: 'text',
        },
        position: 'center',
        type: 'dialog',
        closeOnEscape: true,
        dismissableMask: true,
        draggable: false,
    };
    popupKey = signal('', ...(ngDevMode ? [{ debugName: "popupKey" }] : []));
    lastTarget = null;
    confirm(config) {
        const currentTarget = config?.event?.currentTarget;
        this.popupKey.update((prev) => {
            if (config.type === 'popup') {
                if (this.lastTarget === currentTarget) {
                    return prev || 'popup1';
                }
                return prev === 'popup1' ? 'popup2' : 'popup1';
            }
            return config.type;
        });
        this.lastTarget = currentTarget ?? null;
        this.confirmationService.close();
        const mergedConfig = {
            ...this.defaultConfig,
            ...config,
            target: currentTarget,
            key: this.popupKey(),
        };
        this.confirmationService.confirm(mergedConfig);
    }
    confirmDelete(config) {
        this.confirm({
            message: 'Are you sure you want to delete?',
            header: 'Delete Confirmation',
            icon: 'general.trash-01',
            acceptLabel: 'Delete',
            rejectLabel: 'Cancel',
            acceptButton: {
                severity: 'danger',
            },
            ...config,
        });
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: ConfirmationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: ConfirmationService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: ConfirmationService, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

class ConfirmationDialog {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: ConfirmationDialog, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.0.3", type: ConfirmationDialog, isStandalone: true, selector: "mt-confirmation-dialog", ngImport: i0, template: "<ng-template #popupTemplate let-key=\"key\">\r\n  <p-confirmpopup #cp [key]=\"key\">\r\n    <ng-template #headless let-data>\r\n      <div class=\"flex items-center gap-2 p-3 min-w-100\">\r\n        <div class=\"text-3xl mb-2\">\r\n          <mt-icon [icon]=\"data.icon\"></mt-icon>\r\n        </div>\r\n        <div>{{ data.message }}</div>\r\n      </div>\r\n\r\n      <div class=\"flex items-center justify-end gap-2 p-3 pt-0\">\r\n        <mt-button\r\n          [label]=\"data.acceptLabel\"\r\n          [styleClass]=\"data.acceptButtonStyleClass\"\r\n          [severity]=\"data.acceptButton.severity\"\r\n          [variant]=\"data.acceptButton.variant\"\r\n          size=\"small\"\r\n          (onClick)=\"cp.onAccept()\"\r\n        ></mt-button>\r\n        <mt-button\r\n          [label]=\"data.rejectLabel\"\r\n          [severity]=\"data.rejectButton.severity\"\r\n          [variant]=\"data.rejectButton.variant\"\r\n          size=\"small\"\r\n          (onClick)=\"cp.onReject()\"\r\n        ></mt-button>\r\n      </div>\r\n    </ng-template>\r\n  </p-confirmpopup>\r\n</ng-template>\r\n\r\n<ng-container\r\n  *ngTemplateOutlet=\"popupTemplate; context: { key: 'popup1' }\"\r\n></ng-container>\r\n<ng-container\r\n  *ngTemplateOutlet=\"popupTemplate; context: { key: 'popup2' }\"\r\n></ng-container>\r\n\r\n<p-confirmdialog [key]=\"'dialog'\">\r\n  <ng-template\r\n    #headless\r\n    let-data\r\n    let-onAccept=\"onAccept\"\r\n    let-onReject=\"onReject\"\r\n  >\r\n    <div\r\n      class=\"flex items-center justify-between bg-surface-100 rounded-t-xl px-4 py-2\"\r\n    >\r\n      <div class=\"text-xl font-semibold\">{{ data.header }}</div>\r\n      <mt-button\r\n        [icon]=\"'general.x-close'\"\r\n        variant=\"text\"\r\n        severity=\"secondary\"\r\n        styleClass=\"text-8xl\"\r\n        size=\"large\"\r\n        (onClick)=\"onReject()\"\r\n      ></mt-button>\r\n    </div>\r\n\r\n    <div class=\"flex items-center gap-2 p-4 min-w-100\">\r\n      <div class=\"text-3xl mb-2\">\r\n        <mt-icon [icon]=\"data.icon\"></mt-icon>\r\n      </div>\r\n      <div>{{ data.message }}</div>\r\n    </div>\r\n\r\n    <div class=\"flex items-center justify-end gap-2 mt-2 p-4\">\r\n      <mt-button\r\n        [label]=\"data.acceptLabel\"\r\n        [styleClass]=\"data.acceptButtonStyleClass\"\r\n        [severity]=\"data.acceptButton.severity\"\r\n        [variant]=\"data.acceptButton.variant\"\r\n        (onClick)=\"onAccept()\"\r\n      ></mt-button>\r\n      <mt-button\r\n        [label]=\"data.rejectLabel\"\r\n        [severity]=\"data.rejectButton.severity\"\r\n        [variant]=\"data.rejectButton.variant\"\r\n        (onClick)=\"onReject()\"\r\n      ></mt-button>\r\n    </div>\r\n  </ng-template>\r\n</p-confirmdialog>\r\n", styles: [""], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: ConfirmDialog, selector: "p-confirmDialog, p-confirmdialog, p-confirm-dialog", inputs: ["header", "icon", "message", "style", "styleClass", "maskStyleClass", "acceptIcon", "acceptLabel", "closeAriaLabel", "acceptAriaLabel", "acceptVisible", "rejectIcon", "rejectLabel", "rejectAriaLabel", "rejectVisible", "acceptButtonStyleClass", "rejectButtonStyleClass", "closeOnEscape", "dismissableMask", "blockScroll", "rtl", "closable", "appendTo", "key", "autoZIndex", "baseZIndex", "transitionOptions", "focusTrap", "defaultFocus", "breakpoints", "modal", "visible", "position", "draggable"], outputs: ["onHide"] }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "component", type: Icon, selector: "mt-icon", inputs: ["icon"] }, { kind: "component", type: ConfirmPopup, selector: "p-confirmpopup", inputs: ["key", "defaultFocus", "showTransitionOptions", "hideTransitionOptions", "autoZIndex", "baseZIndex", "style", "styleClass", "visible", "motionOptions", "appendTo"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.0.3", ngImport: i0, type: ConfirmationDialog, decorators: [{
            type: Component,
            args: [{ selector: 'mt-confirmation-dialog', standalone: true, imports: [CommonModule, ConfirmDialog, Button, Icon, ConfirmPopup], template: "<ng-template #popupTemplate let-key=\"key\">\r\n  <p-confirmpopup #cp [key]=\"key\">\r\n    <ng-template #headless let-data>\r\n      <div class=\"flex items-center gap-2 p-3 min-w-100\">\r\n        <div class=\"text-3xl mb-2\">\r\n          <mt-icon [icon]=\"data.icon\"></mt-icon>\r\n        </div>\r\n        <div>{{ data.message }}</div>\r\n      </div>\r\n\r\n      <div class=\"flex items-center justify-end gap-2 p-3 pt-0\">\r\n        <mt-button\r\n          [label]=\"data.acceptLabel\"\r\n          [styleClass]=\"data.acceptButtonStyleClass\"\r\n          [severity]=\"data.acceptButton.severity\"\r\n          [variant]=\"data.acceptButton.variant\"\r\n          size=\"small\"\r\n          (onClick)=\"cp.onAccept()\"\r\n        ></mt-button>\r\n        <mt-button\r\n          [label]=\"data.rejectLabel\"\r\n          [severity]=\"data.rejectButton.severity\"\r\n          [variant]=\"data.rejectButton.variant\"\r\n          size=\"small\"\r\n          (onClick)=\"cp.onReject()\"\r\n        ></mt-button>\r\n      </div>\r\n    </ng-template>\r\n  </p-confirmpopup>\r\n</ng-template>\r\n\r\n<ng-container\r\n  *ngTemplateOutlet=\"popupTemplate; context: { key: 'popup1' }\"\r\n></ng-container>\r\n<ng-container\r\n  *ngTemplateOutlet=\"popupTemplate; context: { key: 'popup2' }\"\r\n></ng-container>\r\n\r\n<p-confirmdialog [key]=\"'dialog'\">\r\n  <ng-template\r\n    #headless\r\n    let-data\r\n    let-onAccept=\"onAccept\"\r\n    let-onReject=\"onReject\"\r\n  >\r\n    <div\r\n      class=\"flex items-center justify-between bg-surface-100 rounded-t-xl px-4 py-2\"\r\n    >\r\n      <div class=\"text-xl font-semibold\">{{ data.header }}</div>\r\n      <mt-button\r\n        [icon]=\"'general.x-close'\"\r\n        variant=\"text\"\r\n        severity=\"secondary\"\r\n        styleClass=\"text-8xl\"\r\n        size=\"large\"\r\n        (onClick)=\"onReject()\"\r\n      ></mt-button>\r\n    </div>\r\n\r\n    <div class=\"flex items-center gap-2 p-4 min-w-100\">\r\n      <div class=\"text-3xl mb-2\">\r\n        <mt-icon [icon]=\"data.icon\"></mt-icon>\r\n      </div>\r\n      <div>{{ data.message }}</div>\r\n    </div>\r\n\r\n    <div class=\"flex items-center justify-end gap-2 mt-2 p-4\">\r\n      <mt-button\r\n        [label]=\"data.acceptLabel\"\r\n        [styleClass]=\"data.acceptButtonStyleClass\"\r\n        [severity]=\"data.acceptButton.severity\"\r\n        [variant]=\"data.acceptButton.variant\"\r\n        (onClick)=\"onAccept()\"\r\n      ></mt-button>\r\n      <mt-button\r\n        [label]=\"data.rejectLabel\"\r\n        [severity]=\"data.rejectButton.severity\"\r\n        [variant]=\"data.rejectButton.variant\"\r\n        (onClick)=\"onReject()\"\r\n      ></mt-button>\r\n    </div>\r\n  </ng-template>\r\n</p-confirmdialog>\r\n" }]
        }] });

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

export { ConfirmationDialog, ConfirmationService };
//# sourceMappingURL=masterteam-components-confirmation.mjs.map
