import { ActionContext } from "vuex" ; export class Notification implements Module { getModule ( ) { return { state : { message : [ ] , confirmMessage : "" , messageIdle : true , notification : "" , } , mutations : { alert : ( state , message ) => { state . message . unshift ( message ) ; } , closeAlert : ( state ) => { state . messageIdle = false ; state . message . shift ( ) ; setTimeout ( ( ) => { state . messageIdle = true ; } , 200 ) ; } , setConfirm : ( state , message ) => { state . confirmMessage = message ; } , setNotification : ( state , message ) => { state . notification = message ; } , } , actions : { confirm : async ( state , message ) => { return new Promise ( ( resolve ) => { state . commit ( "setConfirm" , message ) ; window . addEventListener ( "confirm" , ( event ) => { state . commit ( "setConfirm" , "" ) ; if ( ! this . isCustomEvent ( event ) ) { resolve ( false ) ; return ; } resolve ( event . detail ) ; return ; } ) ; } ) ; } , ephermalMessage : ( state , message ) => { state . commit ( "setNotification" , message ) ; state . commit ( "style/showNotification" , null , { root : true } ) ; } , } , namespaced : true , } ; } private isCustomEvent ( event ) { return "detail" in event ; } }