var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MelodicComponent, html } from '@melodicdev/core';
import { toastTemplate } from './toast.template.js';
import { toastStyles } from './toast.styles.js';
/**
 * ml-toast - Individual toast notification
 *
 * @example
 * ```html
 * <ml-toast variant="success" title="Saved" message="Your changes have been saved."></ml-toast>
 * ```
 *
 * @fires ml:dismiss - Emitted when the toast is dismissed
 */
let ToastComponent = class ToastComponent {
    constructor() {
        /** Toast variant */
        this.variant = 'info';
        /** Toast title */
        this.title = '';
        /** Toast message */
        this.message = '';
        /** Auto-dismiss duration in ms (0 = no auto-dismiss) */
        this.duration = 5000;
        /** Show dismiss button */
        this.dismissible = true;
        this._timer = null;
        this.dismiss = () => {
            if (this._timer) {
                clearTimeout(this._timer);
                this._timer = null;
            }
            this.elementRef.dispatchEvent(new CustomEvent('ml:dismiss', {
                bubbles: true,
                composed: true
            }));
            this.elementRef.remove();
        };
        this.renderIcon = () => {
            const icons = {
                info: 'info',
                success: 'check-circle',
                warning: 'warning',
                error: 'x-circle'
            };
            return html `<ml-icon icon="${icons[this.variant]}"></ml-icon>`;
        };
    }
    onCreate() {
        if (this.duration > 0) {
            this._timer = setTimeout(() => this.dismiss(), this.duration);
        }
    }
};
ToastComponent = __decorate([
    MelodicComponent({
        selector: 'ml-toast',
        template: toastTemplate,
        styles: toastStyles,
        attributes: ['variant', 'title', 'message', 'duration', 'dismissible']
    })
], ToastComponent);
export { ToastComponent };
