import {FC, useEffect, useState} from "react";
import styles from './LeadsPage.module.css';
import Board from "../../../components/Dnd/Board/Board.tsx";
import {DragDropContext} from "@hello-pangea/dnd";
import {useDealSummaries} from "../hooks/useDealSummaries.tsx";
import {DealStatus} from "../../../shared/enums/DealStatus.ts";
import PageBlock from "../../../components/PageBlock/PageBlock.tsx";
import DealEditDrawer from "../drawers/DealEditDrawer/DealEditDrawer.tsx";
import {DealPageContextProvider} from "../contexts/DealPageContext.tsx";


export const LeadsPage: FC = () => {
    const summariesRaw = useDealSummaries();
    const [summaries, setSummaries] = useState(summariesRaw);
    useEffect(() => {
        setSummaries(summariesRaw);
    }, [summariesRaw]);
    const onDragEnd = () => {
        // if (!result.destination) return;
        //
        // const newStatus = getDealStatusByName(
        //     result.destination.droppableId
        // );
        // const summaryId = parseInt(result.draggableId);
        //
        // return;
    }
    return (
        <>
            <DealPageContextProvider>

                <PageBlock>
                    <div className={styles['container']}>
                        <div className={styles['boards']}>
                            <DragDropContext onDragEnd={onDragEnd}>
                                <Board
                                    withCreateButton
                                    summaries={summaries
                                        .filter(summary => summary.status == DealStatus.AWAITING_ACCEPTANCE)}
                                    title={"Ожидает приемки"}
                                    droppableId={"AWAITING_ACCEPTANCE"}
                                />
                                <Board
                                    summaries={summaries
                                        .filter(summary => summary.status == DealStatus.PACKAGING)}
                                    title={"Упаковка"}
                                    droppableId={"PACKAGING"}
                                />
                                <Board
                                    summaries={summaries
                                        .filter(summary => summary.status == DealStatus.AWAITING_SHIPMENT)}
                                    title={"Ожидает отгрузки"}
                                    droppableId={"AWAITING_SHIPMENT"}
                                />
                                <Board
                                    summaries={summaries
                                        .filter(summary => summary.status == DealStatus.AWAITING_PAYMENT)}
                                    title={"Ожидает оплаты"}
                                    droppableId={"AWAITING_PAYMENT"}
                                />
                                <Board
                                    summaries={summaries
                                        .filter(summary => summary.status == DealStatus.COMPLETED)}
                                    title={"Завершена"}
                                    droppableId={"COMPLETED"}
                                />
                            </DragDropContext>
                        </div>
                    </div>
                </PageBlock>
                <DealEditDrawer
                />
            </DealPageContextProvider>

        </>

    )
}
