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> | null> {
    try {
        console.log('activePageUrl', activePageUrl)
        const ApplicationToRender = pageIndexSingle[`/${activePageUrl}`]
        return ApplicationToRender
    } catch (error) {
        console.error('resolveWhichPageToRenderSingle', error)
    }
    return ContentToRenderNoPage
}

async function resolveWhichPageToRenderMulti({ activePageUrl }: ResolverProps): Promise<React.FC<ContentProps> | null> {
    const pageToRender = await retrievePageToRender(activePageUrl)
    try {
        const ApplicationToRender = pageIndexMulti[`${activePageUrl}`][pageToRender]
        return ApplicationToRender
    } catch (error) {
        console.error('resolveWhichPageToRenderMulti', error)
    }
    return ContentToRenderNoPage
}

export { resolveWhichPageToRenderSingle, resolveWhichPageToRenderMulti };
