import React, { FC } from "react";
import { Box, Group, Text } from "@mantine/core";
import { modals } from "@mantine/modals";
import BoardMenu from "@/app/deals/components/shared/BoardMenu/BoardMenu";
import { useBoardsMobileContext } from "@/app/deals/drawers/BoardsMobileEditorDrawer/contexts/BoardsMobileContext";
import { BoardSchema } from "@/lib/client";

type Props = {
    board: BoardSchema;
};

const BoardMobile: FC<Props> = ({ board }) => {
    const { boardsCrud } = useBoardsMobileContext();

    const startEditing = () => {
        modals.openContextModal({
            modal: "enterNameModal",
            title: "Редактирование доски",
            withCloseButton: true,
            innerProps: {
                onChange: values => boardsCrud.onUpdate(board.id, values),
                value: board,
            },
        });
    };

    return (
        <Group
            w={"100%"}
            pr={"md"}
            py={"xs"}
            justify={"space-between"}
            wrap={"nowrap"}>
            <Box>
                <Text>{board.name}</Text>
            </Box>
            <BoardMenu
                board={board}
                startEditing={startEditing}
                onDeleteBoard={boardsCrud.onDelete}
            />
        </Group>
    );
};

export default BoardMobile;
