import { FC } from "react";
import ObjectSelect, { ObjectSelectProps } from "../../../../../components/ObjectSelect/ObjectSelect.tsx";
import { UserSchema } from "../../../../../client";
import useAvailableEmployeesList from "../hooks/useAvailableEmployeesList.tsx";

type DealData = {
    cardId: number;
}

type Props = DealData & Omit<
    ObjectSelectProps<UserSchema | null>,
    "data" | "getValueFn" | "getLabelFn"
>;

const UserForDepartmentSelect: FC<Props> = ({ cardId, ...selectProps }) => {
    const { objects: employees } = useAvailableEmployeesList({ cardId });

    return (
        <ObjectSelect
            data={employees}
            getLabelFn={(user: UserSchema) => `${user.firstName} ${user.secondName}`}
            getValueFn={(user: UserSchema) => user.id.toString()}
            searchable
            {...selectProps}
        />
    );
};
export default UserForDepartmentSelect;
