import type { LocationQueryValue } from "vue-router";
import { router } from "@/router";

export function useNavigateToRedirect(redirect: LocationQueryValue): void;

export function useNavigateToRedirect(redirect: LocationQueryValue[], index: number): void;

export function useNavigateToRedirect(redirect: LocationQueryValue | LocationQueryValue[], index?: number) {
  const _redirect = Array.isArray(redirect) ? redirect[index || 0] as string : redirect as string;
  const path = decodeURIComponent(_redirect || "/");
  router.replace(path);
}
