const t=window.EdelElements.h;var e;!function(t){t.default="info",t.info="info",t.good="good",t.bad="bad",t.warning="warning"}(e||(e={}));const s=[e.info,e.good,e.bad,e.warning];function o(t){return-1!==s.indexOf(t)}class n{constructor(){this.kind=e.default,this.noClose=!1}render(){return[t("div",{class:"toast-icon"},this.renderToastIcon()),t("div",{class:"toast-label"},t("slot",null)),this.noClose?null:this.renderCloseButton()]}hostData(){return{class:"toast"}}componentDidLoad(){this.handleKindChange(this.kind,e.default)}handleKindChange(t,s){!1===o(t)&&(this.kind=e.default),o(s)&&this.host.classList.remove(`toast--${s}`),this.host.classList.add(`toast--${this.kind}`)}renderToastIcon(){const s=(e,s)=>t("i",{class:`fa fa-${e} fa-w-${s}`});switch(this.kind){case e.info:return s("exclamation-triangle",18);case e.good:return s("check-circle",16);case e.bad:return s("times",12);case e.warning:return s("exclamation-triangle",18);default:return null}}renderCloseButton(){return t("div",{class:"toast-action"},t("edel-button",{icon:"times",slim:!0,plain:!0,onEmit:()=>this.close.emit()}))}static get is(){return"edel-toast"}static get properties(){return{host:{elementRef:!0},kind:{type:String,attr:"kind",mutable:!0,watchCallbacks:["handleKindChange"]},noClose:{type:Boolean,attr:"no-close"}}}static get events(){return[{name:"close",method:"close",bubbles:!0,cancelable:!0,composed:!0}]}}class a{constructor(){this.toasts=[],this.duration=1e4,this.canClose=!0,this.now=(()=>Date.now())}hostData(){return{class:"toastgroup"}}render(){return[this.toasts.map(e=>t("edel-toast",{kind:e.kind,"no-close":!e.options.canClose,onClose:e.close},e.message)),t("slot",null)]}cleanExpiredToasts(){const t=this.currentTimestamp();this.removeToastsWhere(e=>0!==e.options.expire&&e.options.expire<=t,!0)}good(t,s={}){return this.presentToast(e.good,t,s)}bad(t,s={}){return this.presentToast(e.bad,t,s)}info(t,s={}){return this.presentToast(e.info,t,s)}warning(t,s={}){return this.presentToast(e.warning,t,s)}componentDidLoad(){this.didLoad.emit(this)}presentToast(t,e,s){const o={message:e,kind:t,options:this.canonicalToastOptions(s),close:()=>this.removeToast(o)};return this.toasts=[o,...this.toasts],this.scheduleCleanFor(o),o}currentTimestamp(){return this.now instanceof Function?this.now():this.now}expiration(t){const e="number"==typeof t.duration?t.duration:this.duration;return 0===e?0:"number"==typeof t.expire?t.expire:this.currentTimestamp()+e}scheduleCleanFor(t){this.now instanceof Function&&setTimeout(()=>this.cleanExpiredToasts(),t.options.expire-this.currentTimestamp())}removeToast(t){this.removeToastsWhere(e=>e===t,!1)}removeToastsWhere(t,e){this.toasts=this.toasts.filter(s=>!t(s)||(s.options.didClose(e),!1))}canonicalToastOptions(t){return{canClose:"boolean"==typeof t.canClose?t.canClose:this.canClose,expire:this.expiration(t),didClose:t.didClose||(()=>void 0)}}static get is(){return"edel-toastgroup"}static get properties(){return{bad:{method:!0},canClose:{type:Boolean,attr:"can-close"},duration:{type:Number,attr:"duration"},good:{method:!0},info:{method:!0},now:{type:Number,attr:"now",watchCallbacks:["cleanExpiredToasts"]},toasts:{state:!0},warning:{method:!0}}}static get events(){return[{name:"didLoad",method:"didLoad",bubbles:!0,cancelable:!0,composed:!0}]}}export{n as EdelToast,a as EdelToastgroup};