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 { Injectable } from '@melodicdev/core';
/**
 * ToastService - Injectable singleton for showing toast notifications from anywhere
 *
 * @example
 * ```typescript
 * @Service(ToastService)
 * private readonly _toastService!: ToastService;
 *
 * this._toastService.success('Saved', 'Your changes have been saved.');
 * this._toastService.error('Error', 'Something went wrong.');
 * this._toastService.show({ variant: 'warning', title: 'Warning', message: '...' });
 * ```
 */
let ToastService = class ToastService {
    constructor() {
        this._containerEl = null;
        this._position = 'top-right';
    }
    /** Set the default position for all toasts */
    setPosition(position) {
        this._position = position;
        if (this._containerEl) {
            this._containerEl.setAttribute('position', position);
        }
    }
    /** Show a toast with full configuration */
    show(config) {
        const container = this.ensureContainer();
        const toast = document.createElement('ml-toast');
        if (config.variant)
            toast.setAttribute('variant', config.variant);
        if (config.title)
            toast.setAttribute('title', config.title);
        if (config.message)
            toast.setAttribute('message', config.message);
        if (config.duration !== undefined)
            toast.setAttribute('duration', String(config.duration));
        if (config.dismissible === false)
            toast.setAttribute('dismissible', 'false');
        container.appendChild(toast);
    }
    /** Show an info toast */
    info(title, message) {
        this.show({ variant: 'info', title, message });
    }
    /** Show a success toast */
    success(title, message) {
        this.show({ variant: 'success', title, message });
    }
    /** Show a warning toast */
    warning(title, message) {
        this.show({ variant: 'warning', title, message });
    }
    /** Show an error toast */
    error(title, message) {
        this.show({ variant: 'error', title, message });
    }
    ensureContainer() {
        if (this._containerEl && document.body.contains(this._containerEl)) {
            return this._containerEl;
        }
        this._containerEl = document.createElement('ml-toast-container');
        this._containerEl.setAttribute('position', this._position);
        document.body.appendChild(this._containerEl);
        return this._containerEl;
    }
};
ToastService = __decorate([
    Injectable()
], ToastService);
export { ToastService };
