'use strict';

var index = require('./index-DuCXzb-X.js');

const spwToastControllerCss = () => `@charset "UTF-8";html{line-height:1.3;-webkit-text-size-adjust:100%;}h1,h2,h3,h4,h5,h6,p,ul,li{padding:0;margin:0}ul{list-style:none}:host{box-sizing:border-box;line-height:1.3;-webkit-text-size-adjust:100%;font-size:100%}:host *,:host *::before,:host *::after{box-sizing:inherit;font-family:var(--spw-ds-font-main)}body{margin:0}hr{box-sizing:content-box;height:0;overflow:visible;}pre{font-family:monospace, monospace;font-size:1em;}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted;}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace, monospace;font-size:1em;}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-0.25em}sup{top:-0.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0;}button,input{overflow:visible}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}button::-moz-focus-inner,[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner{border-style:none;padding:0}button:-moz-focusring,[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:0.35em 0.75em 0.625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal;}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0;}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px;}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit;}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}:root{--spw-ds-container-xl:1232px;--spw-ds-container-lg:1024px;--spw-ds-container-md:768px;--spw-ds-container-sm:640px}.spw-ds-container{width:100%;padding-left:16px;padding-right:16px;margin-left:auto;margin-right:auto}@media (min-width: 460px){.spw-ds-container{max-width:var(--spw-ds-container-sm)}}@media (min-width: 768px){.spw-ds-container{max-width:var(--spw-ds-container-md)}}@media (min-width: 1024px){.spw-ds-container{max-width:var(--spw-ds-container-lg)}}@media (min-width: 1350px){.spw-ds-container{max-width:var(--spw-ds-container-xl)}}:host{display:contents;--spw-toast-controller-gap:10px;--spw-toast-controller-offset:24px;--spw-toast-controller-width:360px;--spw-toast-controller-z-index:999999999}.spw-toast-controller__stack{position:fixed;display:flex;flex-direction:column;gap:var(--spw-toast-controller-gap);z-index:var(--spw-toast-controller-z-index);width:var(--spw-toast-controller-width);max-width:calc(100vw - 2 * var(--spw-toast-controller-offset));pointer-events:none}.spw-toast-controller__stack>*{pointer-events:auto}.spw-toast-controller__stack--top-right{top:var(--spw-toast-controller-offset);right:var(--spw-toast-controller-offset)}.spw-toast-controller__stack--top-left{top:var(--spw-toast-controller-offset);left:var(--spw-toast-controller-offset)}.spw-toast-controller__stack--top-center{top:var(--spw-toast-controller-offset);left:50%;transform:translateX(-50%)}.spw-toast-controller__stack--bottom-right{bottom:var(--spw-toast-controller-offset);right:var(--spw-toast-controller-offset);flex-direction:column-reverse}.spw-toast-controller__stack--bottom-left{bottom:var(--spw-toast-controller-offset);left:var(--spw-toast-controller-offset);flex-direction:column-reverse}.spw-toast-controller__stack--bottom-center{bottom:var(--spw-toast-controller-offset);left:50%;transform:translateX(-50%);flex-direction:column-reverse}`;

const SpwToastController = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        /**
         * Position du conteneur de toasts sur l'écran.
         * Valeurs: 'top-right' | 'top-left' | 'top-center' | 'bottom-right' | 'bottom-left' | 'bottom-center'
         */
        this.position = 'bottom-right';
    }
    /**
     * Crée et affiche un nouveau toast.
     * @returns la référence à l'élément spw-toast créé
     */
    async create(options) {
        var _a;
        const toast = document.createElement('spw-toast');
        if (options.heading)
            toast.heading = options.heading;
        if (options.message)
            toast.message = options.message;
        if (options.linkLabel)
            toast.linkLabel = options.linkLabel;
        if (options.linkHref)
            toast.linkHref = options.linkHref;
        if (options.icon)
            toast.icon = options.icon;
        toast.variant = (_a = options.variant) !== null && _a !== void 0 ? _a : 'default';
        toast.duration = options.duration !== undefined ? options.duration : 5000;
        toast.dismissable = options.dismissable !== undefined ? options.dismissable : true;
        if (options.onLinkClick) {
            toast.addEventListener('spwToastLinkClick', options.onLinkClick);
        }
        this.stackEl.appendChild(toast);
        return toast;
    }
    /**
     * Ferme tous les toasts affichés.
     */
    async dismissAll() {
        const toasts = Array.from(this.stackEl.querySelectorAll('spw-toast'));
        await Promise.all(toasts.map(t => { var _a; return (_a = t.dismiss) === null || _a === void 0 ? void 0 : _a.call(t); }));
    }
    render() {
        return (index.h(index.Host, { key: 'b320fb0051b98993b6d40809ac3c4eb8f9607d43' }, index.h("div", { key: '6709e4ece4e9f39f0c1e53e78331814b5281aa43', class: {
                'spw-toast-controller__stack': true,
                [`spw-toast-controller__stack--${this.position}`]: true,
            }, "aria-label": "Notifications", ref: el => (this.stackEl = el) })));
    }
};
SpwToastController.style = spwToastControllerCss();

exports.spw_toast_controller = SpwToastController;
