import { createSelector } from 'reselect';
import { denormalize } from 'normalizr';
import mapValues from 'lodash/mapValues';

import teamSchema from './schema';

const selectPlayers = state => state.data.players;

export const selectTeam = (state, props) => state.data.teams.byId[props.teamId];
export const selectTeams = state => state.data.teams;
export const selectTeamPlayerItems = (state, props) => state.data.teams.byId[props.teamId].players;

export const selectDenormalizedTeams = createSelector(
  [selectTeams, selectPlayers],
  (teams, players) => {
    const data = { teams, players };
    return denormalize(
      Object.keys(teams.byId),
      [teamSchema],
      { ...mapValues(data, value => value.byId) },
    );
  },
);

@@ -343,16 +343,17 @@
 .teams;%0A
+%0A
 export c
@@ -403,51 +403,87 @@
  =%3E 
+%7B%0A  con
 st
-ate.data.teams.byId%5Bprops.teamId%5D.players
+ team = selectTeam(state, props);%0A  return team ? team.players : %5B%5D;%0A%7D
 ;%0A%0Ae

Reset response errors when a new tactic is created