import UrlUtils from "~/services/utils/urlUtils";

export const useRedirect = () => {
    const runtimeConfig = useRuntimeConfig()

    const redirectToLogout = () => {
        if (!runtimeConfig.baseUrlAdminLegacy) {
            throw new Error('Configuration error : no redirection target')
        }
        navigateTo(UrlUtils.join(runtimeConfig.baseUrlAdminLegacy, '#/logout'), {external: true})
    }

    const redirectToHome = () => {
        if (!runtimeConfig.baseUrlAdminLegacy) {
            throw new Error('Configuration error : no redirection target')
        }
        navigateTo(UrlUtils.join(runtimeConfig.baseUrlAdminLegacy, '#/dashboard'), {external: true})
    }

    return { redirectToLogout, redirectToHome }
}
