class s{constructor(s,t,e){switch(this.stateValue=s,this.messageValue=t,this.task=e,this.listeners=[],s){case"delayed":this.timer=window.setTimeout(()=>this.execute(),5e3);break;case"executing":this.execute();break;case"success":case"warning":case"failed":this.startCloseTimer()}}get state(){return this.stateValue}set state(s){this.stateValue!=s&&(this.stateValue=s,this.emit())}get message(){return this.messageValue}set message(s){this.messageValue!=s&&(this.messageValue=s,this.emit())}listen(s){this.listeners.push(s)}unlisten(s){this.listeners.filter(t=>t!=s)}emit(){this.listeners.forEach(s=>s(this))}execute(){this.clearTimer(),this.task?(this.state="executing",this.task(this).then(s=>{this.messageValue=s[1],this.state=s[0]?"success":"failed",this.startCloseTimer()})):this.state="failed"}startCloseTimer(){this.timer=window.setTimeout(()=>this.close(),15e3)}close(){this.clearTimer(),this.state="closed"}clearTimer(){this.timer&&(window.clearTimeout(this.timer),this.timer=void 0)}static delay(t,e){return new s("delayed",t,e)}static execute(t,e){return new s("executing",t,e)}static succeded(t){return new s("success",t)}static failed(t){return new s("failed",t)}static warn(t){return new s("warning",t)}}export{s as N}