import { RootState } from "app/store";

export const selectTypistGroups = (state: RootState) =>
  state.typistGroup.domain.typistGroups;

export const selectIsLoading = (state: RootState) =>
  state.typistGroup.apps.isLoading;

export const selectTypists = (state: RootState) =>
  state.typistGroup.domain.typists;

export const selectPoolTypists = (state: RootState) =>
  state.typistGroup.domain.typists.filter(
    (t) => !state.typistGroup.apps.selectedTypists.some((x) => t.id === x.id)
  );

export const selectSelectedTypists = (state: RootState) =>
  state.typistGroup.apps.selectedTypists;

export const selectGroupName = (state: RootState) =>
  state.typistGroup.apps.groupName;

export const selectAddGroupErrors = (state: RootState) => {
  const hasErrorEmptyGroupName = state.typistGroup.apps.groupName === "";
  const hasErrorSelectedTypistsEmpty =
    state.typistGroup.apps.selectedTypists.length === 0;

  return { hasErrorEmptyGroupName, hasErrorSelectedTypistsEmpty };
};
