import React from "react";
import { ResolverProps } from "@/validations/mutual/resolvers/validations";
import { retrievePageToRender } from "@/hooks/application/hook";
import { ContentProps } from "@/validations/mutual/dashboard/props";

import pageIndexMulti from "@/pages/multi/index";
import pageIndexSingle from "@/pages/single/index";
import ContentToRenderNoPage from "@/pages/mutual/noContent/page";

async function resolveWhichPageToRenderSingle({ activePageUrl }: ResolverProps): Promise<React.FC<ContentProps> | React.FC<{ lang: string }> | null> {
    try {
        return `${activePageUrl}` in pageIndexSingle ? pageIndexSingle[`${activePageUrl}`] : ContentToRenderNoPage
    } catch (error) {
        console.error(error)
    }
    return ContentToRenderNoPage
}

async function resolveWhichPageToRenderMulti({ activePageUrl }: ResolverProps): Promise<React.FC<ContentProps> | React.FC<{ lang: string }> | null> {
    const pageToRender = await retrievePageToRender(activePageUrl)        // TODO: Retrieve page to render
    try {
        const ApplicationToRender = pageIndexMulti[activePageUrl][pageToRender]
        return ApplicationToRender
    } catch (error) {
        console.error(error)
    }
    return ContentToRenderNoPage
}

export { resolveWhichPageToRenderSingle, resolveWhichPageToRenderMulti };
