import { autoRouteTable } from "@/router/constants/auto-route-table";
import { FUNNEL_START_PAGE } from "@/router/constants/routes";
import { checkPagePrerequisites } from "@/router/methods/page-prerequisites";

export async function autoRouteBeforeEnter(to, from) {
    for (let i = 0; i < autoRouteTable.length; i++) {
        const testRouteData = autoRouteTable[i];

        const isReady = await checkPagePrerequisites(testRouteData.name);

        if (isReady) {
            return {
                name: testRouteData.name,
                replace: true,
            };
        }
    }

    return {
        name: FUNNEL_START_PAGE,
        replace: true,
    };
}
