/*!
 * KoliBri - The accessible HTML-Standard
 */
import{h as t,r as s,H as e}from"./index-b2c61df0.js";import{t as o}from"./i18n-112381e9.js";import{n as a}from"./dev.utils-a14ff412.js";import{k as i,o as n}from"./component-names-068dc2ae.js";import"./i18n-66b52d13.js";import"./reuse-b66836de.js";import"./dev.utils-1ca991a2.js";const c=({key:s,onClose:e,onRef:a,toastState:o})=>t("div",{class:`toast ${o.status}`,key:s},t(i,{class:"alert",_alert:!0,_label:o.toast.label,_level:0,_hasCloser:!0,_type:o.toast.type,_variant:o.toast.alertVariant||"card",_on:{onClose:e}},t("div",{ref:a},"string"==typeof o.toast.description?o.toast.description:null))),l="@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}",r=l,h=300,f=class{constructor(t){s(this,t),this.knownRenderFunctions=new Set,this.state={_toastStates:[]}}async enqueue(t){const s={toast:t,status:"adding",id:`toast-${a()}`};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))})}),h),()=>{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))})}),h)}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))))})}),h)}}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 t(e,{key:"36c5561666fee5691aa7f732dcd90f5e4fe75457",class:"kol-toast-container"},this.state._toastStates.length>1&&t(n,{key:"fe4187d5afff3547776ba89b695386bef8e05c93",_label:o("kol-toast-close-all"),class:"close-all",_on:{onClick:()=>{this.closeAll()}}}),this.state._toastStates.map((s=>t(c,{key:s.id,onClose:()=>this.handleClose(s),onRef:t=>this.handleToastRef(s,t),toastState:s}))))}};f.style={default:r};export{f as kol_toast_container};