"use client";

import { Box, Space } from "@mantine/core";
import DealsTable from "@/app/deals/components/desktop/DealsTable/DealsTable";
import MainBlockHeader from "@/app/deals/components/mobile/MainBlockHeader/MainBlockHeader";
import Funnel from "@/app/deals/components/shared/Funnel/Funnel";
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
import { DealsContextProvider } from "@/app/deals/contexts/DealsContext";
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
import { useViewContext } from "@/app/deals/contexts/ViewContext";

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

    if (view === "board") {
        return (
            <>
                <MainBlockHeader />
                <Space h={"md"} />
                <DealsContextProvider boardId={selectedBoard?.id}>
                    <Funnel />
                </DealsContextProvider>
            </>
        );
    }

    if (view === "table") {
        return (
            <Box>
                <DealsContextProvider
                    withPagination
                    projectId={selectedProject?.id}>
                    <DealsTable />
                </DealsContextProvider>
            </Box>
        );
    }

    return <>-</>;
};

export default PageBody;
