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