import { useMemo } from 'react';
import { ROLE_ID_STYTCH_MEMBER } from './roles.mjs';
import { useRoleDisplayInfo } from './useRoleDisplayInfo.mjs';
import { useRoles } from './useRoles.mjs';
import { useRoleSortFn } from './useRoleSortFn.mjs';

const useRoleAutocomplete = ({ excludeStytchMember = false, includeOrgRoles = false } = {})=>{
    const allRoles = useRoles(includeOrgRoles);
    const assignableRoles = useMemo(()=>excludeStytchMember ? allRoles?.filter((role)=>role.role_id !== ROLE_ID_STYTCH_MEMBER) : allRoles, [
        allRoles,
        excludeStytchMember
    ]);
    const sortRoles = useRoleSortFn();
    const roleSelectItems = useMemo(()=>{
        return sortRoles(assignableRoles ?? []).map((role)=>role.role_id);
    }, [
        assignableRoles,
        sortRoles
    ]);
    const { roleInfo, getRoleIdDisplayName } = useRoleDisplayInfo(includeOrgRoles);
    return {
        selectItems: roleSelectItems,
        getOptionDescription: (roleId)=>roleInfo[roleId].description,
        getOptionLabel: getRoleIdDisplayName
    };
};

export { useRoleAutocomplete };
//# sourceMappingURL=useRoleAutocomplete.mjs.map
