'use server';
import { FC } from "react";
import { joinPageUrlFromLayersArray, retrieveLayersOfUrlFromParams } from "@/lib/menuGet";
import { dynamicPagesIndex } from "@/languages/custom";
import { retrieveAvailableApplicationList, langDynamicPagesGet, langGet } from "@/lib/langGet";
import { DashboardLayoutProps, ModeTypes } from "@/validations/mutual/dashboard/props";

import HeaderComponent from "@/components/custom/header/component";
import MenuComponent from "@/components/custom/menu/component";
import ContentComponent from "@/components/custom/content/component";
import FooterComponent from "@/components/custom/footer/component";

const DashboardLayout: FC<DashboardLayoutProps> = async ({ params, searchParams, lang }) => {
    const layersItems = retrieveLayersOfUrlFromParams(params.page);
    const activePageUrl = joinPageUrlFromLayersArray(layersItems.data);

    const mode = (searchParams?.mode as ModeTypes) || 'shortList';
    const availableApplications = await retrieveAvailableApplicationList(lang);

    const translations = langGet(lang, langDynamicPagesGet(activePageUrl, dynamicPagesIndex));

    const headerProps = { translations: translations.header, lang, activePageUrl, prefix: "/panel" }
    const menuProps = { lang, activePageUrl, availableApplications }
    const contentProps = { translations: translations.content, lang, activePageUrl, mode, isMulti: true }

    return (
        <div className="flex flex-col min-w-screen">
            <HeaderComponent {...headerProps} />
            <MenuComponent {...menuProps} />
            <ContentComponent {...contentProps} />
            <FooterComponent translations={translations.footer} />
        </div>
    );
}

export { DashboardLayout };
