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(t,e,i){super(t),this.title=e,this.message=i}close(){this.addClass("hiding"),setTimeout((()=>this.parent.removeChild(this)),500)}async build(){let t,e=await super.build(),i=E.i().class("fas fa-times");return e.content(E.h2().content(this.title),E.p().content(this.message),i),t=setTimeout((()=>this.close()),5e3),e.on("mouseenter",(()=>{clearTimeout(t)})),i.on("click",(()=>this.close())),e}}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(t){super(t);for(let t of["error","warn","info"])this[t]=(e,i)=>this.push(t,e,i)}push(t,e,i){let s;null===i?s="[null]":i instanceof Error?(console.error(i),s=i.toString()):s="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 o={error:ErrorNotificationView,warn:WarnNotificationView,info:InfoNotificationView}[t.toLowerCase()];return this.addChild(o,e,s)}}export{NotificationCenterView};
