import { FC } from "react";
import ObjectSelect, { ObjectSelectProps } from "../ObjectSelect/ObjectSelect.tsx";
import { UserSchema } from "../../client";
import useManagersList from "../../pages/CardsPage/hooks/useManagersList.tsx";

type Props = Omit<
    ObjectSelectProps<UserSchema | null>,
    "data" | "getValueFn" | "getLabelFn"
>;
const ManagerSelect: FC<Props> = props => {
    const { objects: managers } = useManagersList();
    return (
        <ObjectSelect
            data={managers}
            getLabelFn={(manager: UserSchema) => `${manager.firstName} ${manager.secondName}`}
            getValueFn={(manager: UserSchema) => manager.id.toString()}
            clearable
            searchable
            {...props}
            onClear={() => props.onChange(null)}
        />
    );
};
export default ManagerSelect;
