import { $store, $eventbus } from "@racletteCore/main"

export default () => {
  const notifications = $store.getState(["notifications", "items"])
  if (Object.keys(notifications).length) {
    const checkTokenNotifications = Object.values(notifications).filter(
      (item) => {
        return item.event === "checkToken" && item.state === "unread"
      },
    )

    if (checkTokenNotifications.length) {
      $eventbus.emit("ui/addToSnackbar", checkTokenNotifications[0].message)
      $store.dispatch({
        type: "notifications/markAllAsRead",
      })
    }
  }
}
