import * as i0 from '@angular/core';
import { EventEmitter, Component, Input, Output, HostBinding, NgModule, inject, ApplicationRef, Injector, ComponentFactoryResolver, Injectable } from '@angular/core';
import { CommonModule } from '@angular/common';
import { first } from 'rxjs/operators';

/**
 * @description Componente individual de notificação (toast) que exibe uma mensagem temporária na tela.
 * Gerencia automaticamente o timer de dismiss quando `toast.sticky` é `false`.
 * Recomenda-se utilizar o `ToastService` para criar e empilhar toasts na aplicação.
 *
 * @example
 * ```html
 * <s-toast [toast]="toastData" (dismiss)="onDismiss()" />
 * ```
 *
 * @category Feedback
 */
class ToastComponent {
    /**
     * @description Objeto com os dados da notificação a ser exibida.
     * Inclui propriedades como `severity`, `summary`, `detail`, `duration` e `sticky`.
     */
    toast;
    /**
     * @description Emitido quando a notificação é descartada, seja pelo timer automático
     * (ao expirar `toast.duration`) ou pela ação manual do usuário.
     */
    dismiss = new EventEmitter();
    isLeaving = false;
    timer = null;
    ngOnInit() {
        if (!this.toast.sticky && this.toast.duration) {
            this.timer = setTimeout(() => {
                this.startDismissAnimation();
            }, this.toast.duration);
        }
    }
    ngOnDestroy() {
        if (this.timer) {
            clearTimeout(this.timer);
        }
    }
    startDismissAnimation() {
        this.isLeaving = true;
        setTimeout(() => {
            this.dismiss.emit();
        }, 300);
    }
    dismissToast() {
        if (this.timer) {
            clearTimeout(this.timer);
        }
        this.startDismissAnimation();
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToastComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: ToastComponent, selector: "s-toast", inputs: { toast: "toast" }, outputs: { dismiss: "dismiss" }, host: { properties: { "class.toast--leaving": "this.isLeaving" } }, ngImport: i0, template: "<div\n    class=\"toast\"\n    [class.toast--info]=\"toast.severity === 'info'\"\n    [class.toast--success]=\"toast.severity === 'success'\"\n    [class.toast--warning]=\"toast.severity === 'warning'\"\n    [class.toast--error]=\"toast.severity === 'error'\"\n>\n    <div class=\"toast-content\">\n        <i\n            class=\"toast-icon fas fa-info\"\n            [class.fa-info]=\"toast.severity === 'info'\"\n            [class.fa-check]=\"toast.severity === 'success'\"\n            [class.fa-exclamation-triangle]=\"toast.severity === 'warning'\"\n            [class.fa-times]=\"toast.severity === 'error'\"\n        ></i>\n        <div class=\"text-container\">\n            @if(toast.title) {\n                <span class=\"toast-summary\" [innerHTML]=\"toast.title\"></span>\n            }\n            @if(toast.text) {\n                <span [innerHTML]=\"toast.text\"></span>\n            }\n        </div>\n    </div>\n    @if(toast.closable) {\n        <button class=\"toast-close-button\" (click)=\"dismissToast()\"><i class=\"fas fa-times\"></i></button>\n    }\n</div>\n", styles: [":host{display:block}.toast{align-items:center;animation:fadeInDown .3s forwards;border-left:3px solid #428bca;border-radius:3px;box-shadow:0 1px 5px #00000040;color:#212533;display:flex;font-family:\"Open Sans\" sans-serif;font-size:14px;opacity:0;padding:10px 15px;position:relative;transform:translateY(-20px);width:400px}.toast .toast-content{align-items:center;flex-grow:1;display:flex;gap:15px}.toast .toast-content .toast-icon{align-items:center;background-color:#428bca;border-radius:50%;color:#fff;display:flex;flex-shrink:0;height:40px;justify-content:center;width:40px}.toast .toast-content .text-container{display:flex;flex-direction:column}.toast .toast-content .text-container .toast-summary{font-weight:700}.toast--success{background-color:#e0f0f0;border-left:3px solid #0c9348}.toast--success .toast-content .toast-icon{background-color:#0c9348}.toast--error{background-color:#fef0f0;border-left:3px solid #c13018}.toast--error .toast-content .toast-icon{background-color:#c13018}.toast--info{background-color:#f1f7f8;border-left:3px solid #428bca}.toast--info .toast-content .toast-icon{background-color:#428bca}.toast--warning{background-color:#fef4e3;border-left:3px solid #fcbf10}.toast--warning .toast-content .toast-icon{background-color:#fcbf10;color:#212533}.toast-close-button{background:none;border:none;color:#212533;font-size:1rem;cursor:pointer;margin-left:15px;transition:transform .2s ease-in-out}.toast-close-button:hover{transform:scale(1.1)}@keyframes fadeInDown{0%{opacity:0;transform:translateY(-20px)}to{opacity:1;transform:translateY(0)}}@keyframes fadeOutUp{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-20px)}}:host.toast--leaving{animation:fadeOutUp .3s forwards}@media (max-width: 440px){.toast{width:calc(100% - 40px)}}\n"] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToastComponent, decorators: [{
            type: Component,
            args: [{ selector: 's-toast', template: "<div\n    class=\"toast\"\n    [class.toast--info]=\"toast.severity === 'info'\"\n    [class.toast--success]=\"toast.severity === 'success'\"\n    [class.toast--warning]=\"toast.severity === 'warning'\"\n    [class.toast--error]=\"toast.severity === 'error'\"\n>\n    <div class=\"toast-content\">\n        <i\n            class=\"toast-icon fas fa-info\"\n            [class.fa-info]=\"toast.severity === 'info'\"\n            [class.fa-check]=\"toast.severity === 'success'\"\n            [class.fa-exclamation-triangle]=\"toast.severity === 'warning'\"\n            [class.fa-times]=\"toast.severity === 'error'\"\n        ></i>\n        <div class=\"text-container\">\n            @if(toast.title) {\n                <span class=\"toast-summary\" [innerHTML]=\"toast.title\"></span>\n            }\n            @if(toast.text) {\n                <span [innerHTML]=\"toast.text\"></span>\n            }\n        </div>\n    </div>\n    @if(toast.closable) {\n        <button class=\"toast-close-button\" (click)=\"dismissToast()\"><i class=\"fas fa-times\"></i></button>\n    }\n</div>\n", styles: [":host{display:block}.toast{align-items:center;animation:fadeInDown .3s forwards;border-left:3px solid #428bca;border-radius:3px;box-shadow:0 1px 5px #00000040;color:#212533;display:flex;font-family:\"Open Sans\" sans-serif;font-size:14px;opacity:0;padding:10px 15px;position:relative;transform:translateY(-20px);width:400px}.toast .toast-content{align-items:center;flex-grow:1;display:flex;gap:15px}.toast .toast-content .toast-icon{align-items:center;background-color:#428bca;border-radius:50%;color:#fff;display:flex;flex-shrink:0;height:40px;justify-content:center;width:40px}.toast .toast-content .text-container{display:flex;flex-direction:column}.toast .toast-content .text-container .toast-summary{font-weight:700}.toast--success{background-color:#e0f0f0;border-left:3px solid #0c9348}.toast--success .toast-content .toast-icon{background-color:#0c9348}.toast--error{background-color:#fef0f0;border-left:3px solid #c13018}.toast--error .toast-content .toast-icon{background-color:#c13018}.toast--info{background-color:#f1f7f8;border-left:3px solid #428bca}.toast--info .toast-content .toast-icon{background-color:#428bca}.toast--warning{background-color:#fef4e3;border-left:3px solid #fcbf10}.toast--warning .toast-content .toast-icon{background-color:#fcbf10;color:#212533}.toast-close-button{background:none;border:none;color:#212533;font-size:1rem;cursor:pointer;margin-left:15px;transition:transform .2s ease-in-out}.toast-close-button:hover{transform:scale(1.1)}@keyframes fadeInDown{0%{opacity:0;transform:translateY(-20px)}to{opacity:1;transform:translateY(0)}}@keyframes fadeOutUp{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-20px)}}:host.toast--leaving{animation:fadeOutUp .3s forwards}@media (max-width: 440px){.toast{width:calc(100% - 40px)}}\n"] }]
        }], propDecorators: { toast: [{
                type: Input
            }], dismiss: [{
                type: Output
            }], isLeaving: [{
                type: HostBinding,
                args: ['class.toast--leaving']
            }] } });

class ToastModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToastModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.14", ngImport: i0, type: ToastModule, declarations: [ToastComponent], imports: [CommonModule] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToastModule, imports: [CommonModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToastModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [CommonModule],
                    declarations: [ToastComponent],
                }]
        }] });

class ToastService {
    appRef = inject(ApplicationRef);
    injector = inject(Injector);
    componentFactoryResolver = inject(ComponentFactoryResolver);
    activeToasts = [];
    globalToastHostElement = null;
    ensureGlobalToastHost() {
        if (!this.globalToastHostElement) {
            this.globalToastHostElement = document.createElement("div");
            document.body.appendChild(this.globalToastHostElement);
            this.globalToastHostElement.style.display = "flex";
            this.globalToastHostElement.style.flexDirection = "column";
            this.globalToastHostElement.style.position = "fixed";
            this.globalToastHostElement.style.right = "20px";
            this.globalToastHostElement.style.top = "20px";
            this.globalToastHostElement.style.zIndex = "99999";
            this.globalToastHostElement.style.gap = "10px";
        }
    }
    show(toast) {
        this.ensureGlobalToastHost();
        const componentFactory = this.componentFactoryResolver.resolveComponentFactory(ToastComponent);
        const componentRef = componentFactory.create(this.injector);
        this.appRef.attachView(componentRef.hostView);
        if (!toast.sticky) {
            toast.duration = toast.duration ?? 10000;
        }
        componentRef.instance.toast = {
            closable: true,
            ...toast,
        };
        const domElem = componentRef.hostView.rootNodes[0];
        this.globalToastHostElement.appendChild(domElem);
        domElem.style.display = "flex";
        domElem.style.justifyContent = "center";
        componentRef.instance.dismiss.pipe(first()).subscribe(() => {
            const index = this.activeToasts.indexOf(componentRef);
            if (index !== -1) {
                this.appRef.detachView(componentRef.hostView);
                componentRef.destroy();
                this.activeToasts.splice(index, 1);
            }
            if (this.activeToasts.length === 0 && this.globalToastHostElement) {
                this.globalToastHostElement.remove();
                this.globalToastHostElement = null;
            }
        });
        this.activeToasts.push(componentRef);
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToastService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
    static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToastService, providedIn: "root" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToastService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: "root",
                }]
        }] });

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

export { ToastComponent, ToastModule, ToastService };
//# sourceMappingURL=seniorsistemas-angular-components-toast.mjs.map
