import{h}from"../edel-elements.core.js";var ToastKind;!function(t){t.default="info",t.info="info",t.good="good",t.bad="bad",t.warning="warning"}(ToastKind||(ToastKind={}));var allToastKinds=[ToastKind.info,ToastKind.good,ToastKind.bad,ToastKind.warning];function isToastKind(t){return-1!==allToastKinds.indexOf(t)}var EdelToastComponent=function(){function t(){this.kind=ToastKind.default,this.noClose=!1}return t.prototype.render=function(){return[h("div",{class:"toast-icon"},this.renderToastIcon()),h("div",{class:"toast-label"},h("slot",null)),this.noClose?null:this.renderCloseButton()]},t.prototype.hostData=function(){return{class:"toast"}},t.prototype.componentDidLoad=function(){this.handleKindChange(this.kind,ToastKind.default)},t.prototype.handleKindChange=function(t,o){!1===isToastKind(t)&&(this.kind=ToastKind.default),isToastKind(o)&&this.host.classList.remove("toast--"+o),this.host.classList.add("toast--"+this.kind)},t.prototype.renderToastIcon=function(){var t=function(t,o){return h("i",{class:"fa fa-"+t+" fa-w-"+o})};switch(this.kind){case ToastKind.info:return t("exclamation-triangle",18);case ToastKind.good:return t("check-circle",16);case ToastKind.bad:return t("times",12);case ToastKind.warning:return t("exclamation-triangle",18);default:return null}},t.prototype.renderCloseButton=function(){var t=this;return h("div",{class:"toast-action"},h("edel-button",{icon:"times",slim:!0,plain:!0,onEmit:function(){return t.close.emit()}}))},Object.defineProperty(t,"is",{get:function(){return"edel-toast"},enumerable:!0,configurable:!0}),Object.defineProperty(t,"properties",{get:function(){return{host:{elementRef:!0},kind:{type:String,attr:"kind",mutable:!0,watchCallbacks:["handleKindChange"]},noClose:{type:Boolean,attr:"no-close"}}},enumerable:!0,configurable:!0}),Object.defineProperty(t,"events",{get:function(){return[{name:"close",method:"close",bubbles:!0,cancelable:!0,composed:!0}]},enumerable:!0,configurable:!0}),t}(),EdelToastgroupComponent=function(){function t(){this.toasts=[],this.duration=1e4,this.canClose=!0,this.now=function(){return Date.now()}}return t.prototype.hostData=function(){return{class:"toastgroup"}},t.prototype.render=function(){return[this.toasts.map(function(t){return h("edel-toast",{kind:t.kind,"no-close":!t.options.canClose,onClose:t.close},t.message)}),h("slot",null)]},t.prototype.cleanExpiredToasts=function(){var t=this.currentTimestamp();this.removeToastsWhere(function(o){return 0!==o.options.expire&&o.options.expire<=t},!0)},t.prototype.good=function(t,o){return void 0===o&&(o={}),this.presentToast(ToastKind.good,t,o)},t.prototype.bad=function(t,o){return void 0===o&&(o={}),this.presentToast(ToastKind.bad,t,o)},t.prototype.info=function(t,o){return void 0===o&&(o={}),this.presentToast(ToastKind.info,t,o)},t.prototype.warning=function(t,o){return void 0===o&&(o={}),this.presentToast(ToastKind.warning,t,o)},t.prototype.componentDidLoad=function(){this.didLoad.emit(this)},t.prototype.presentToast=function(t,o,n){var e=this,i={message:o,kind:t,options:this.canonicalToastOptions(n),close:function(){return e.removeToast(i)}};return this.toasts=[i].concat(this.toasts),this.scheduleCleanFor(i),i},t.prototype.currentTimestamp=function(){return this.now instanceof Function?this.now():this.now},t.prototype.expiration=function(t){var o="number"==typeof t.duration?t.duration:this.duration;return 0===o?0:"number"==typeof t.expire?t.expire:this.currentTimestamp()+o},t.prototype.scheduleCleanFor=function(t){var o=this;this.now instanceof Function&&setTimeout(function(){return o.cleanExpiredToasts()},t.options.expire-this.currentTimestamp())},t.prototype.removeToast=function(t){this.removeToastsWhere(function(o){return o===t},!1)},t.prototype.removeToastsWhere=function(t,o){this.toasts=this.toasts.filter(function(n){return!t(n)||(n.options.didClose(o),!1)})},t.prototype.canonicalToastOptions=function(t){return{canClose:"boolean"==typeof t.canClose?t.canClose:this.canClose,expire:this.expiration(t),didClose:t.didClose||function(){}}},Object.defineProperty(t,"is",{get:function(){return"edel-toastgroup"},enumerable:!0,configurable:!0}),Object.defineProperty(t,"properties",{get:function(){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}}},enumerable:!0,configurable:!0}),Object.defineProperty(t,"events",{get:function(){return[{name:"didLoad",method:"didLoad",bubbles:!0,cancelable:!0,composed:!0}]},enumerable:!0,configurable:!0}),t}();export{EdelToastComponent as EdelToast,EdelToastgroupComponent as EdelToastgroup};