"use client";

import { Box } from "@mantine/core";
import TopToolPanel from "@/app/deals/components/desktop/TopToolPanel/TopToolPanel";
import {
    BoardView,
    ScheduleView,
    TableView,
} from "@/app/deals/components/shared/views";
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
import { DealsContextProvider } from "@/app/deals/contexts/DealsContext";
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
import useView from "@/app/deals/hooks/useView";
import PageBlock from "@/components/layout/PageBlock/PageBlock";

const PageBody = () => {
    const { selectedBoard } = useBoardsContext();
    const { selectedProject } = useProjectsContext();

    const { view, setView } = useView();

    const getViewContent = () => {
        switch (view) {
            case "board":
                return <BoardView />;
            case "table":
                return <TableView />;
            default:
                return <ScheduleView />;
        }
    };

    const getContextProps = () => {
        if (view === "table") {
            return { withPagination: true, projectId: selectedProject?.id };
        }
        return { boardId: selectedBoard?.id, projectId: selectedProject?.id };
    };

    return (
        <DealsContextProvider {...getContextProps()}>
            <TopToolPanel
                view={view}
                setView={setView}
            />
            <PageBlock
                fullScreenMobile
                style={{ flex: 1 }}>
                <Box h={"100%"}>{getViewContent()}</Box>
            </PageBlock>
        </DealsContextProvider>
    );
};

export default PageBody;
