import { VISIBILITY_FILTERS } from "../constants";

export const getTasksState = (store) => store.tasks;

export const getTaskList = (store) =>
  getTasksState(store) ? getTasksState(store).allIds : [];

export const getTasksById = (store, id) =>
  getTasksState(store) ? { ...getTasksState(store).byIds[id], id } : {};

export const getTasks = (store) =>
  getTaskList(store).map((id) => getTasksById(store, id));

export const getTasksByVisibilityFilter = (store, visibilityFilter) => {
  const allTasks = getTasks(store);
  switch (visibilityFilter) {
    case VISIBILITY_FILTERS.COMPLETED:
      console.log("contains completed tasks");
      return allTasks.filter((task) => task.completed);
    case VISIBILITY_FILTERS.INCOMPLETE:
      console.log("contains uncompleted tasks");
      return allTasks.filter((task) => !task.completed);
    case VISIBILITY_FILTERS.ALL:
    default:
      return allTasks;
  }
};
