import { BaseTransactionTagSchema } from "../../../../../client";
import { Button, Stack, TextInput } from "@mantine/core";
import { useState } from "react";
import { notifications } from "../../../../../shared/lib/notifications.ts";


type Props = {
    onCreate: (tag: BaseTransactionTagSchema) => void;
    isIncome: boolean;
}

const CreateTransactionTagForm = ({ onCreate, isIncome }: Props) => {
    const [transactionTag, setTransactionTag] = useState<string>("");

    const onCreateClick = () => {
        if (transactionTag.length === 0) {
            notifications.error({ message: "Нельзя добавить тег без названия" });
            return;
        }
        onCreate({
            name: transactionTag,
            isIncome: isIncome,
        });
        setTransactionTag("");
    };

    return (
        <Stack>
            <TextInput
                label={"Добавить тег"}
                value={transactionTag}
                onChange={event => setTransactionTag(event.target.value)}
            />
            <Button
                variant={"default"}
                onClick={onCreateClick}>
                Добавить
            </Button>
        </Stack>
    );
};

export default CreateTransactionTagForm;