/*!
 * KoliBri - The accessible HTML-Standard
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const index=require("./index-277fc2a7.js"),i18n=require("./i18n-b46c3c64.js"),dev_utils=require("./dev.utils-0390f767.js"),componentNames=require("./component-names-4a2d0b57.js");require("./i18n-737701e2.js"),require("./reuse-50a5792c.js"),require("./dev.utils-58fde089.js");const InternalToast=({key:t,onClose:e,onRef:s,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:e}},index.h("div",{ref:s},"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 e={toast:t,status:"adding",id:`toast-${dev_utils.nonce()}`};return this.state=Object.assign(Object.assign({},this.state),{_toastStates:[e,...this.state._toastStates]}),setTimeout((()=>{this.state=Object.assign(Object.assign({},this.state),{_toastStates:this.state._toastStates.map((t=>t.id===e.id&&"removing"!==t.status?Object.assign(Object.assign({},t),{status:"settled"}):t))})}),300),()=>{this.handleClose(e)}}handleClose(t){this.state=Object.assign(Object.assign({},this.state),{_toastStates:this.state._toastStates.map((e=>(e.id===t.id&&(e.status="removing"),e)))}),setTimeout((()=>{this.state=Object.assign(Object.assign({},this.state),{_toastStates:this.state._toastStates.filter((e=>e.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((e=>t.every((t=>t.id!==e.id))))})}),300)}}handleToastRef(t,e){e&&"function"==typeof t.toast.render&&!this.knownRenderFunctions.has(t.toast.render)&&(this.knownRenderFunctions.add(t.toast.render),t.toast.render(e,{close:()=>this.handleClose(t)}))}render(){return index.h(index.Host,{key:"69ede64a0d0e5bfcd817e943d5a7cb4512c4deb4",class:"kol-toast-container"},this.state._toastStates.length>1&&index.h(componentNames.KolButtonTag,{key:"a05a1e8f4e8f3609ea815dfce9110f59791fa82e",_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:e=>this.handleToastRef(t,e),toastState:t}))))}};KolToastContainer.style={default:KolToastContainerDefaultStyle0},exports.kol_toast_container=KolToastContainer;