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 { useStatusesContext } from "@/app/deals/contexts/StatusesContext";
import { StatusSchema } from "@/lib/client";

type Props = {
    status: StatusSchema;
};

const StatusMobile: FC<Props> = ({ status }) => {
    const { onUpdateStatus } = useStatusesContext();

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

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

export default StatusMobile;
