import{View,ParentView}from"./base.mjs";import{ElementBuilder}from"../base/builder.mjs";import{isEmpty}from"../base/helpers.mjs";const E=new ElementBuilder,hideDelay=500,autoCloseDelay=5e3;class NotificationView extends View{static tagName="enfugue-notification";constructor(e,t,i){super(e),this.title=t,this.message=i}close(){this.addClass("hiding"),setTimeout((()=>this.parent.removeChild(this)),500)}async build(){let e,t=await super.build(),i=E.i().class("fas fa-times");return t.content(E.h2().content(this.title),E.p().content(this.message),i),e=setTimeout((()=>this.close()),5e3),t.on("mouseenter",(()=>{clearTimeout(e)})),i.on("click",(()=>this.close())),t}}class ErrorNotificationView extends NotificationView{static className="error"}class WarnNotificationView extends NotificationView{static className="warn"}class InfoNotificationView extends NotificationView{static className="info"}class NotificationCenterView extends ParentView{static tagName="enfugue-notification-center";constructor(e){super(e);for(let e of["error","warn","info"])this[e]=(t,i)=>this.push(e,t,i)}push(e,t,i){let o;null===i?o="[null]":i instanceof Error?(console.error(i),o=i.toString()):o="string"==typeof i?i:"object"==typeof i?isEmpty(i.errors)?isEmpty(i.title)?JSON.stringify(i):`${i.title}: ${i.detail}`:`${i.errors[0].title}: ${i.errors[0].detail}`:`${i}`;let s={error:ErrorNotificationView,warn:WarnNotificationView,info:InfoNotificationView}[e.toLowerCase()];return isEmpty(s)&&(console.error(`Bad level ${e}, using error.`),console.trace(),s=ErrorNotificationView),this.addChild(s,t,o)}}export{NotificationCenterView};
