import{b as s}from"./p-b9dddc6c.js";import{i as t}from"./p-522b3f33.js";import{i}from"./p-42fa5fb2.js";import{b as e}from"./p-cb2be791.js";class o{constructor(s){this.options=s,this.container=null,this.queue=[],this.preQueue=[],this.queueLimit=5}create(t){if(s.hasDocument){this.setupContainer();const s=this.findClone(t);if(void 0===s){const s=document.createElement(this.options.tag);return Object.assign(s,t),s.addEventListener("balClose",(s=>{this.removeFromQueue(s.detail)})),this.preQueue.push(s),this.updateQueue(),s}return s}}setQueue(s){this.queueLimit=s}async dismissAll(){var s;const t=null===(s=this.container)||void 0===s?void 0:s.querySelectorAll(this.options.tag);if(t){const s=[];for(let i=0;i<t.length;i++){const e=t[i];e.close&&s.push(e.close())}await Promise.all(s)}}async clearAll(){return console.warn("[DEPRECATED] - use dismissAll() instead"),this.dismissAll()}findClone(s){for(let t=0;t<this.queue.length;t++){const i=this.queue[t];if(i.message===s.message&&i.color===s.color)return i}}setupContainer(){if(s.hasDocument){const s=`${this.options.tag}-container`;if(this.container=document.getElementById(s),this.container)return;this.container||(this.container=document.createElement("bal-notices"),this.container.setAttribute("interface",this.options.tag.replace("bal-","")),this.container.id=s),document.body.appendChild(this.container)}}updateQueue(){var s;if(this.queue.length<this.queueLimit){const s=this.preQueue.shift();s&&this.container&&(this.queue.push(s),this.container.insertAdjacentElement("beforeend",s))}0===this.queue.length&&(null===(s=this.container)||void 0===s||s.remove())}removeFromQueue(s){this.queue=this.queue.filter((t=>t.id!==s)),setTimeout((()=>this.updateQueue()),0)}}class n extends o{constructor(){super({tag:"bal-toast"})}create(s){return super.create(s)}}const r=new n;class a extends o{constructor(){super({tag:"bal-snackbar"})}create(s){return super.create(s)}}const c=new a,l=(o={})=>{if(s.hasWindow){const n=window;n.BaloiseDesignSystem=n.BaloiseDesignSystem||{},t(o,n),e.detect(),n.BaloiseDesignSystem.toastController=r,n.BaloiseDesignSystem.snackbarController=c,n.BaloiseDesignSystem.initialize=()=>t(n.BaloiseDesignSystem.config,n),n.BaloiseDesignSystem.version="14.3.0";const a=()=>{if(s.hasDocument){const s=document.querySelector(".bal-body");s&&s.classList&&s.classList.add("is-ready")}};if(n.addEventListener){let s=!1,t="css";const e=document.querySelector(".bal-app");e&&(s=""===(null==e?void 0:e.getAttribute("ready")),null!==(null==e?void 0:e.getAttribute("mode"))&&(t=null==e?void 0:e.getAttribute("mode"))),i(t),s?a():n.addEventListener("balAppLoad",(()=>a()))}}};export{n as B,a,r as b,c,l as i}