import { FC } from "react";
import { Flex, ScrollArea } from "@mantine/core";
import DealServiceRow from "@/modules/dealModularEditorTabs/FulfillmentBase/desktop/components/DealServicesTable/components/DealServiceRow";
import DealServicesTitle from "@/modules/dealModularEditorTabs/FulfillmentBase/desktop/components/DealServicesTable/components/DealServicesTitle";
import ServicesActions from "@/modules/dealModularEditorTabs/FulfillmentBase/desktop/components/DealServicesTable/components/ServicesActions";
import DealServicesTotalLabel from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/components/DealServicesTotalLabel/DealServicesTotalLabel";
import { useFulfillmentBaseContext } from "@/modules/dealModularEditorTabs/FulfillmentBase/shared/contexts/FulfillmentBaseContext";

const DealServicesTable: FC = () => {
    const { dealServicesList, dealServicesCrud } = useFulfillmentBaseContext();

    return (
        <Flex
            direction={"column"}
            gap={"sm"}
            h={"78vh"}>
            <DealServicesTitle />
            <ScrollArea
                flex={1}
                scrollbars={"y"}
                offsetScrollbars={"present"}>
                <Flex
                    direction={"column"}
                    gap={"sm"}>
                    {dealServicesList.dealServices.map(dealService => (
                        <DealServiceRow
                            key={dealService.service.id}
                            value={dealService}
                            onDelete={dealServicesCrud.onDelete}
                            onChange={dealServicesCrud.onUpdate}
                        />
                    ))}
                </Flex>
            </ScrollArea>
            <DealServicesTotalLabel mt={"sm"} />
            <ServicesActions />
        </Flex>
    );
};
export default DealServicesTable;
