export { getAssetPath, setAssetPath, setNonce, setPlatformOptions } from '@stencil/core/internal/client';
import { L as Lang } from './lang.js';
import { g as getNotificationContainerElement } from './helpers.js';
import { S as Store, T as Theme, Q as Query } from './theme.js';
import { E as Errors } from './errors.js';
import { D as Dialog } from './dialog.js';

const MAX_ELEMENTS_ON_CONTAINER = 4;
class NotificationService {
    constructor(topContainer = null, bottomContainer = null) {
        this.topContainer = topContainer;
        this.bottomContainer = bottomContainer;
        this.topContainer = getNotificationContainerElement('top');
        this.bottomContainer = getNotificationContainerElement('bottom');
    }
    call(options) {
        if (typeof options === 'string') {
            this.prepareNotification({
                message: options,
            });
        }
        else {
            this.prepareNotification(options);
        }
    }
    shouldQueue(options) {
        if (!this.topContainer && options.position === 'top') {
            this.topContainer = getNotificationContainerElement('top');
        }
        if (!this.bottomContainer && options.position === 'bottom') {
            this.bottomContainer = getNotificationContainerElement('bottom');
        }
        return (options.position === 'bottom' ? this.bottomContainer : this.topContainer).childElementCount >= MAX_ELEMENTS_ON_CONTAINER;
    }
    prepareNotification(options) {
        if (this.shouldQueue(options)) {
            setTimeout(() => this.prepareNotification(options), 250);
        }
        else {
            const el = document.createElement('x-notification');
            if (options.label) {
                const label = document.createElement('h4');
                label.innerText = options.label;
                el.appendChild(label);
            }
            if (options.onclose) {
                el.addEventListener('close', options.onclose);
            }
            const message = document.createElement('p');
            message.innerHTML = options.message;
            el.appendChild(message);
            options.color && el.setAttribute('color', options.color);
            options.icon && el.setAttribute('icon', options.icon);
            options.interval && el.setAttribute('interval', options.interval.toString());
            (options.position === 'bottom' ? this.bottomContainer : this.topContainer).insertAdjacentElement('afterbegin', el);
        }
    }
    success(message, label, icon, interval) {
        this.prepareNotification({
            color: 'success',
            label: label || Lang('alert.success'),
            message,
            icon,
            interval,
        });
    }
    fail(message, label, icon, interval) {
        this.prepareNotification({
            color: 'danger',
            label: label || Lang('alert.danger'),
            message,
            icon,
            interval,
        });
    }
    static create() {
        const instance = new NotificationService();
        return Object.assign((options) => instance.call(options), {
            success: (message, label, icon, interval) => instance.success(message, label, icon, interval),
            fail: (message, label, icon, interval) => instance.fail(message, label, icon, interval)
        });
    }
}
const Notification = NotificationService.create();

window.lang = Lang;
window.notification = Notification;
window.store = Store;
window.theme = Theme;
window.query = Query;
window.errors = Errors;
window.dialog = Dialog;
const Services = {
    lang: Lang,
    notification: Notification,
    store: Store,
    theme: Theme,
    query: Query,
    errors: Errors,
    dialog: Dialog,
};

const UI = Services;

export { UI };
