"use client";

import { useState } from "react";
import TopToolPanel, {
    View,
} 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";

const PageBody = () => {
    const { selectedBoard } = useBoardsContext();
    const { selectedProject } = useProjectsContext();
    const [view, setView] = useState<View>("board");

    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 };
    };

    return (
        <DealsContextProvider {...getContextProps()}>
            <TopToolPanel
                view={view}
                setView={setView}
            />
            {getViewContent()}
        </DealsContextProvider>
    );
};

export default PageBody;
