import{a as t}from"./p-90108212.js";import{b as s}from"./p-e680e7e4.js";import{d as e}from"./p-e7a581f5.js";class i{constructor(t){this.options=t,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",(t=>{this.removeFromQueue(t.detail)})),this.preQueue.push(s),this.updateQueue(),s}return s}}setQueue(t){this.queueLimit=t}async dismissAll(){var t;const s=null===(t=this.container)||void 0===t?void 0:t.querySelectorAll(this.options.tag);if(s){const t=[];for(let e=0;e<s.length;e++){const i=s[e];i.close&&t.push(i.close())}await Promise.all(t)}}async clearAll(){return console.warn("[DEPRECATED] - use dismissAll() instead"),this.dismissAll()}findClone(t){for(let s=0;s<this.queue.length;s++){const e=this.queue[s];if(e.message===t.message&&e.color===t.color)return e}}setupContainer(){if(s.hasDocument){const t=`${this.options.tag}-container`;if(this.container=document.getElementById(t),this.container)return;this.container||(this.container=document.createElement("bal-notices"),this.container.setAttribute("interface",this.options.tag.replace("bal-","")),this.container.id=t),document.body.appendChild(this.container)}}updateQueue(){var t;if(this.queue.length<this.queueLimit){const t=this.preQueue.shift();t&&this.container&&(this.queue.push(t),this.container.insertAdjacentElement("beforeend",t))}0===this.queue.length&&(null===(t=this.container)||void 0===t||t.remove())}removeFromQueue(t){this.queue=this.queue.filter((s=>s.id!==t)),setTimeout((()=>this.updateQueue()),0)}}class n extends i{constructor(){super({tag:"bal-toast"})}create(t){return super.create(t)}}const r=new n;class h extends i{constructor(){super({tag:"bal-snackbar"})}create(t){return super.create(t)}}const o=new h,c="baloise-persist-config",a=new class{constructor(){this._componentObservers=[],this._observers=[],this._config=e}get locale(){return`${this._config.language}-${this._config.region}`}get region(){return this._config.region}set region(t){t!==this._config.region&&(this._config.region=t,this._notify())}get language(){return this._config.language}set language(t){t!==this._config.language&&(this._config.language=this._config.allowedLanguages.includes(t)?t:this._config.fallbackLanguage,this._notify())}get allowedLanguages(){return this._config.allowedLanguages}set allowedLanguages(t){t!==this._config.allowedLanguages&&(this._config.allowedLanguages=t,this._notify())}get icons(){return this._config.icons}set icons(t){this._config.icons=Object.assign(Object.assign({},this._config.icons),t),this._notify()}get logger(){return this._config.logger}set logger(t){this._config.logger=Object.assign({},t),this._notify()}get animated(){return this._config.animated}set animated(t){this._config.animated=t,this._notify()}attach(t){if(this._observers.includes(t))return console.log("Subject: Observer has been attached already.");this._observers.push(t),t.configChanged(this._config)}detach(t){const s=this._observers.indexOf(t);if(-1===s)return console.log("Subject: Nonexistent observer.");this._observers.splice(s,1)}attachComponent(t){if(this._componentObservers.includes(t))return console.log("Subject: Observer has been attached already.");this._componentObservers.push(t),t.configChanged(this._config)}detachComponent(t){const s=this._componentObservers.indexOf(t);if(-1===s)return console.log("Subject: Nonexistent observer.");this._componentObservers.splice(s,1)}toString(){return JSON.stringify(this._config)}reset(t){this._config=Object.assign(Object.assign(Object.assign({},this._config),t),{icons:Object.assign(Object.assign({},this._config.icons),t.icons)}),this._notify(!1)}_notify(t=!0){for(const t of this._componentObservers)t.configChanged(this._config);if(t)for(const t of this._observers)t.configChanged(this._config);s.hasWindow&&l(window,this._config)}},u=t=>{try{const s=t.sessionStorage.getItem(c);return null!==s?JSON.parse(s):{}}catch(t){return{}}},l=(t,s)=>{try{t.sessionStorage.setItem(c,JSON.stringify(s))}catch(t){return}},b=(t={},e={})=>{0===Object.keys(e).length&&s.hasWindow&&(e=window),e.BaloiseDesignSystem=e.BaloiseDesignSystem||{},a.reset(Object.assign(Object.assign(Object.assign({},u(e)),t),{icons:Object.assign(Object.assign({},u(e).icons),t.icons)})),e.BaloiseDesignSystem.config=a},d=(e={},i,n={})=>{0===Object.keys(n).length&&s.hasWindow&&(n=window),n.BaloiseDesignSystem=n.BaloiseDesignSystem||{},i&&t(i),b(Object.assign(Object.assign({},e),i),n),n.BaloiseDesignSystem.toastController=r,n.BaloiseDesignSystem.snackbarController=o,n.BaloiseDesignSystem.initialize=()=>b(n.BaloiseDesignSystem.config,n),n.BaloiseDesignSystem.version="15.0.1"};export{n as B,h as a,r as b,o as c,d as i,b as s}