import{a as t}from"./p-9c6e275c.js";import{L as s}from"./p-a0c4df1d.js";import{T as o}from"./p-02206696.js";class e{constructor(s=null,o=null){this.topContainer=s,this.bottomContainer=o,this.topContainer=t("top"),this.bottomContainer=t("bottom")}call(t){this.prepareNotification("string"==typeof t?{message:t}:t)}calculateItemsByPosition(t){if(this.topContainer&&"top"===t){const t=this.topContainer.childElementCount;this.topContainer.classList.remove("more-odd","more-even"),t>1&&this.topContainer.classList.add("more-odd"),t>2&&this.topContainer.classList.add("more-even")}if(this.bottomContainer&&"bottom"===t){const t=this.bottomContainer.childElementCount;this.bottomContainer.classList.remove("more-odd","more-even"),t>1&&this.bottomContainer.classList.add("more-odd"),t>2&&this.bottomContainer.classList.add("more-even")}}shouldQueue(s){return this.topContainer||"top"!==s.position||(this.topContainer=t("top"),this.topContainer.addEventListener("slotchange",(()=>console.log("change")))),this.bottomContainer||"bottom"!==s.position||(this.bottomContainer=t("bottom")),("bottom"===s.position?this.bottomContainer:this.topContainer).childElementCount>=(o.isMobile()?1:4)}prepareNotification(t){var s;if(this.shouldQueue(t))setTimeout((()=>this.prepareNotification(t)),250);else{const o=document.createElement("x-notification");if(t.label){const s=document.createElement("h4");s.innerText=t.label,o.appendChild(s)}t.onclose&&o.addEventListener("close",t.onclose);const e=document.createElement("p");e.innerHTML=t.message,o.appendChild(e),t.color&&o.setAttribute("color",t.color),t.icon&&o.setAttribute("icon",t.icon),t.interval&&o.setAttribute("interval",t.interval.toString()),("bottom"===t.position?this.bottomContainer:this.topContainer).insertAdjacentElement("afterbegin",o),this.calculateItemsByPosition(null!==(s=t.position)&&void 0!==s?s:"top")}}success(t,o,e,i){this.prepareNotification({color:"success",label:o||s("alert.success"),message:t,icon:e,interval:i})}fail(t,o,e,i){this.prepareNotification({color:"danger",label:o||s("alert.danger"),message:t,icon:e,interval:i})}static create(){const t=new e;return Object.assign((s=>t.call(s)),{success:(s,o,e,i)=>t.success(s,o,e,i),fail:(s,o,e,i)=>t.fail(s,o,e,i)})}}const i=e.create();export{i as N}