import{__awaiter,__extends,__generator}from"tslib";import{b as balBrowser}from"./browser-216e7b03.js";import{i as initialize}from"./initialize-7bec2c8a.js";import{i as initStyleMode}from"./mode-75877e6e.js";import{b as balBreakpoints}from"./breakpoints.subject-2c93aba1.js";var BalNoticeController=function(){function t(t){this.options=t;this.container=null;this.queue=[];this.preQueue=[];this.queueLimit=5}t.prototype.create=function(t){var i=this;if(balBrowser.hasDocument){this.setupContainer();var r=this.findClone(t);if(r===undefined){var n=document.createElement(this.options.tag);Object.assign(n,t);n.addEventListener("balClose",(function(t){i.removeFromQueue(t.detail)}));this.preQueue.push(n);this.updateQueue();return n}return r}};t.prototype.setQueue=function(t){this.queueLimit=t};t.prototype.dismissAll=function(){return __awaiter(this,void 0,void 0,(function(){var t,i,r,n,o;return __generator(this,(function(e){switch(e.label){case 0:i=(t=this.container)===null||t===void 0?void 0:t.querySelectorAll(this.options.tag);if(!i)return[3,2];r=[];for(n=0;n<i.length;n++){o=i[n];if(o.close){r.push(o.close())}}return[4,Promise.all(r)];case 1:e.sent();e.label=2;case 2:return[2]}}))}))};t.prototype.clearAll=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){console.warn("[DEPRECATED] - use dismissAll() instead");return[2,this.dismissAll()]}))}))};t.prototype.findClone=function(t){for(var i=0;i<this.queue.length;i++){var r=this.queue[i];if(r.message===t.message&&r.color===t.color){return r}}return undefined};t.prototype.setupContainer=function(){if(balBrowser.hasDocument){var t="".concat(this.options.tag,"-container");this.container=document.getElementById(t);if(this.container)return;if(!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)}};t.prototype.updateQueue=function(){var t;if(this.queue.length<this.queueLimit){var i=this.preQueue.shift();if(i&&this.container){this.queue.push(i);this.container.insertAdjacentElement("beforeend",i)}}if(this.queue.length===0){(t=this.container)===null||t===void 0?void 0:t.remove()}};t.prototype.removeFromQueue=function(t){var i=this;this.queue=this.queue.filter((function(i){return i.id!==t}));setTimeout((function(){return i.updateQueue()}),0)};return t}();var BalToastController=function(t){__extends(i,t);function i(){return t.call(this,{tag:"bal-toast"})||this}i.prototype.create=function(i){return t.prototype.create.call(this,i)};return i}(BalNoticeController);var balToastController=new BalToastController;var BalSnackbarController=function(t){__extends(i,t);function i(){return t.call(this,{tag:"bal-snackbar"})||this}i.prototype.create=function(i){return t.prototype.create.call(this,i)};return i}(BalNoticeController);var balSnackbarController=new BalSnackbarController;var VERSION="14.3.0";var initializeBaloiseDesignSystem=function(t){if(t===void 0){t={}}if(balBrowser.hasWindow){var i=window;i.BaloiseDesignSystem=i.BaloiseDesignSystem||{};initialize(t,i);balBreakpoints.detect();i.BaloiseDesignSystem.toastController=balToastController;i.BaloiseDesignSystem.snackbarController=balSnackbarController;i.BaloiseDesignSystem.initialize=function(){return initialize(i.BaloiseDesignSystem.config,i)};i.BaloiseDesignSystem.version=VERSION;var r=function(){if(balBrowser.hasDocument){var t=document.querySelector(".bal-body");if(t&&t.classList){t.classList.add("is-ready")}}};if(i.addEventListener){var n=false;var o="css";var e=document.querySelector(".bal-app");if(e){n=(e===null||e===void 0?void 0:e.getAttribute("ready"))==="";if((e===null||e===void 0?void 0:e.getAttribute("mode"))!==null){o=e===null||e===void 0?void 0:e.getAttribute("mode")}}initStyleMode(o);if(n){r()}else{i.addEventListener("balAppLoad",(function(){return r()}))}}}};export{BalToastController as B,BalSnackbarController as a,balToastController as b,balSnackbarController as c,initializeBaloiseDesignSystem as i};