import { FC } from "react";
import { TransactionTagSchema } from "../../../../client";
import ObjectSelect, { ObjectSelectProps } from "../../../../components/ObjectSelect/ObjectSelect.tsx";
import useAllTransactionTagsList from "../../../AdminPage/hooks/useAllTransactionTagsList.tsx";

type IsIncome = {
    isIncome: boolean;
}
type Props = Omit<
    ObjectSelectProps<TransactionTagSchema | null>,
    "data" | "getValueFn" | "getLabelFn"
> & IsIncome;
const TransactionTagSelect: FC<Props> = props => {
    let { objects: tags } = useAllTransactionTagsList();
    tags = tags.filter(tag => tag.isIncome === props.isIncome);

    return (
        <ObjectSelect
            data={tags}
            getLabelFn={(tag: TransactionTagSchema) => tag.name}
            getValueFn={(tag: TransactionTagSchema) => tag.id.toString()}
            clearable
            {...props}
            onClear={() => props.onChange(null)}
        />
    );
};
export default TransactionTagSelect;
