import { createSelector } from 'reselect';
import { GROUP } from '../data/entityTypes';
import { userGroupIdsSelector } from './userAccountSelectors';
/**
* Selects member groups
*/
export const userGroupsSelector = createSelector(
state => state.entities[GROUP] || null,
userGroupIdsSelector,
(groupsEntity, groupIds) =>
groupsEntity &&
Object.values(groupsEntity).filter(group => groupIds.some(groupId => groupId === group.id)),
);
/**
* Selects the members first group
* - A member should only ever be able to join one group however the api returns an array of groups
*/
export const userGroupSelector = createSelector(
state => state.entities[GROUP] || null,
userGroupIdsSelector,
(groupsEntity, groupIds) => groupsEntity && groupsEntity[groupIds[0]],
);