/*!
 * KoliBri - The accessible HTML-Standard
 */
import{h,proxyCustomElement,HTMLElement,Host}from"@stencil/core/internal/client";import{t as translate}from"./i18n2.js";import{n as nonce}from"./dev.utils.js";import{k as KolAlertTag,n as KolButtonTag}from"./component-names.js";const InternalToast=({toastState:t,onClose:s,key:e})=>h("div",{class:`toast ${t.status}`,key:e},h(KolAlertTag,{class:"alert",_alert:!0,_label:t.toast.label,_level:0,_hasCloser:!0,_type:t.toast.type,_variant:t.toast.alertVariant||"card",_on:{onClose:s}},h("div",{ref:e=>{"function"==typeof t.toast.render&&e&&t.toast.render(e,{close:()=>s()})}},"string"==typeof t.toast.description?t.toast.description:null))),defaultStyleCss="@layer kol-component {\n  :host {\n    display: flex;\n    flex-direction: column;\n    position: fixed;\n    z-index: 200;\n  }\n  .close-all {\n    align-self: flex-end;\n  }\n}",KolToastContainerDefaultStyle0=defaultStyleCss,TRANSITION_TIMEOUT=300,KolToastContainer$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.state={_toastStates:[]}}async enqueue(t){const s={toast:t,status:"adding",id:`toast-${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?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(){this.state=Object.assign(Object.assign({},this.state),{_toastStates:this.state._toastStates.map((t=>Object.assign(Object.assign({},t),{status:"removing"})))}),setTimeout((()=>{this.state=Object.assign(Object.assign({},this.state),{_toastStates:[]})}),300)}render(){return h(Host,{key:"f07fd5109ed0d409e24587c68ff6b6ac22029c77",class:"kol-toast-container"},this.state._toastStates.length>1&&h(KolButtonTag,{_label:translate("kol-toast-close-all"),class:"close-all",_on:{onClick:()=>{this.closeAll()}}}),this.state._toastStates.map((t=>h(InternalToast,{toastState:t,onClose:()=>this.handleClose(t),key:t.id}))))}static get style(){return{default:KolToastContainerDefaultStyle0}}},[33,"kol-toast-container",{state:[32],enqueue:[64],closeAll:[64]}]);function defineCustomElement$1(){if("undefined"==typeof customElements)return;["kol-toast-container"].forEach((t=>{if("kol-toast-container"===t)customElements.get(t)||customElements.define(t,KolToastContainer$1)}))}const KolToastContainer=KolToastContainer$1,defineCustomElement=defineCustomElement$1;export{KolToastContainer,defineCustomElement};