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 { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
import { BoardSchema } from "@/lib/client";

type Props = {
    board: BoardSchema;
};

const BoardMobile: FC<Props> = ({ board }) => {
    const { onUpdateBoard } = useBoardsContext();

    const startEditing = () => {
        modals.openContextModal({
            modal: "enterNameModal",
            title: "Редактирование доски",
            withCloseButton: true,
            innerProps: {
                onComplete: name => onUpdateBoard(board.id, { name }),
                defaultValue: board.name,
            },
        });
    };

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

export default BoardMobile;
