/*!
 * KoliBri - The accessible HTML-Standard
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const index=require("./index-5cf289dd.js"),i18n=require("./i18n-86815e80.js"),dev_utils=require("./dev.utils-cf2db529.js"),componentNames=require("./component-names-b370a3a3.js");require("./i18n-bbd0642f.js"),require("./reuse-daa2baf3.js"),require("./dev.utils-3e595d38.js");const InternalToast=({key:t,onClose:s,onRef:e,toastState:a})=>index.h("div",{class:`toast ${a.status}`,key:t},index.h(componentNames.KolAlertTag,{class:"alert",_alert:!0,_label:a.toast.label,_level:0,_hasCloser:!0,_type:a.toast.type,_variant:a.toast.alertVariant||"card",_on:{onClose:s}},index.h("div",{ref:e},"string"==typeof a.toast.description?a.toast.description:null))),defaultStyleCss="@layer kol-component {\n  :host {\n    display: flex;\n    flex-direction: column;\n    font-size: calc(16rem / var(--kolibri-root-font-size, 16));\n    position: fixed;\n    z-index: 200;\n  }\n  .close-all {\n    align-self: flex-end;\n  }\n}",KolToastContainerDefaultStyle0=defaultStyleCss,TRANSITION_TIMEOUT=300,KolToastContainer=class{constructor(t){index.registerInstance(this,t),this.knownRenderFunctions=new Set,this.state={_toastStates:[]}}async enqueue(t){const s={toast:t,status:"adding",id:`toast-${dev_utils.nonce()}`};return this.state=Object.assign(Object.assign({},this.state),{_toastStates:[s,...this.state._toastStates]}),setTimeout((()=>{this.state=Object.assign(Object.assign({},this.state),{_toastStates:this.state._toastStates.map((t=>t.id===s.id&&"removing"!==t.status?Object.assign(Object.assign({},t),{status:"settled"}):t))})}),300),()=>{this.handleClose(s)}}handleClose(t){this.state=Object.assign(Object.assign({},this.state),{_toastStates:this.state._toastStates.map((s=>(s.id===t.id&&(s.status="removing"),s)))}),setTimeout((()=>{this.state=Object.assign(Object.assign({},this.state),{_toastStates:this.state._toastStates.filter((s=>s.id!==t.id))})}),300)}async closeAll(t=!1){if(t)this.state=Object.assign(Object.assign({},this.state),{_toastStates:[]});else{const t=[...this.state._toastStates];this.state=Object.assign(Object.assign({},this.state),{_toastStates:t.map((t=>Object.assign(Object.assign({},t),{status:"removing"})))}),setTimeout((()=>{this.state=Object.assign(Object.assign({},this.state),{_toastStates:this.state._toastStates.filter((s=>t.every((t=>t.id!==s.id))))})}),300)}}handleToastRef(t,s){s&&"function"==typeof t.toast.render&&!this.knownRenderFunctions.has(t.toast.render)&&(this.knownRenderFunctions.add(t.toast.render),t.toast.render(s,{close:()=>this.handleClose(t)}))}render(){return index.h(index.Host,{key:"36c5561666fee5691aa7f732dcd90f5e4fe75457",class:"kol-toast-container"},this.state._toastStates.length>1&&index.h(componentNames.KolButtonTag,{key:"fe4187d5afff3547776ba89b695386bef8e05c93",_label:i18n.translate("kol-toast-close-all"),class:"close-all",_on:{onClick:()=>{this.closeAll()}}}),this.state._toastStates.map((t=>index.h(InternalToast,{key:t.id,onClose:()=>this.handleClose(t),onRef:s=>this.handleToastRef(t,s),toastState:t}))))}};KolToastContainer.style={default:KolToastContainerDefaultStyle0},exports.kol_toast_container=KolToastContainer;