import type { Router } from 'vue-router'

let router: Router | null = null

export function setRouter(r: Router): void {
  router = r
}

export function goLogin(redirect: string): void {
  if (router) {
    router.push({ name: 'login', query: { redirect } })
  } else {
    window.location.assign(
      `/?redirect=${encodeURIComponent(redirect)}#/login`,
    )
  }
}
