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

type SectionData = {
    sectionid: number;
}

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

const UserForDepartmentSelect: FC<Props> = props => {
    const { objects: users } = useAvailableUsersList({ sectionId: props.sectionid });

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