import { hitDatabaseSelector, databaseFilterSettingsSelector } from './index';
import { createSelector } from 'reselect';
import { HitDatabaseEntry, HitDatabaseMap, StatusFilterType } from 'types';
import { filterBy } from 'utils/databaseFilter';
import { Map } from 'immutable';

export const hitDatabaseFilteredBySearchTerm = createSelector(
  [hitDatabaseSelector, databaseFilterSettingsSelector],
  (hitDatabase, { searchTerm }) =>
    hitDatabase
      .filter((hit: HitDatabaseEntry) => hit.title.search(searchTerm) !== -1)
      .map((el: HitDatabaseEntry) => el.id)
);

export const hitDatabaseFilteredByStatus = createSelector(
  [hitDatabaseSelector, databaseFilterSettingsSelector],
  (hitDatabase, { statusFilters }) => {
    if (statusFilters.isEmpty()) {
      return hitDatabase;
    }

    const filterFunction = filterBy(hitDatabase);

    const resultsMaps = statusFilters.reduce(
      (acc: HitDatabaseMap[], cur: StatusFilterType) =>
        acc.concat(filterFunction(cur)),
      []
    );

    return resultsMaps
      .reduce(
        (acc: HitDatabaseMap, cur: HitDatabaseMap) => acc.merge(cur),
        Map()
      )
      .map((el: HitDatabaseEntry) => el.id)
      .toArray();
  }
);

import { hitDatabaseSelector, databaseFIlterSettingsSelector } from './index';
import { createSelector } from 'reselect';
import { HitDatabaseEntry } from 'types';

export const hitDatabaseFilteredBySearchTerm = createSelector(
  [hitDatabaseSelector, databaseFIlterSettingsSelector],
  (hitDatabase, { searchTerm }) =>
    hitDatabase
      .filter((hit: HitDatabaseEntry) => hit.title.search(searchTerm) !== -1)
      .map((el: HitDatabaseEntry) => el.id)
);

--- 
+++ 
@@ -1,11 +1,38 @@
-import { hitDatabaseSelector, databaseFIlterSettingsSelector } from './index';
+import { hitDatabaseSelector, databaseFilterSettingsSelector } from './index';
 import { createSelector } from 'reselect';
-import { HitDatabaseEntry } from 'types';
+import { HitDatabaseEntry, HitDatabaseMap, StatusFilterType } from 'types';
+import { filterBy } from 'utils/databaseFilter';
+import { Map } from 'immutable';
 
 export const hitDatabaseFilteredBySearchTerm = createSelector(
-  [hitDatabaseSelector, databaseFIlterSettingsSelector],
+  [hitDatabaseSelector, databaseFilterSettingsSelector],
   (hitDatabase, { searchTerm }) =>
     hitDatabase
       .filter((hit: HitDatabaseEntry) => hit.title.search(searchTerm) !== -1)
       .map((el: HitDatabaseEntry) => el.id)
 );
+
+export const hitDatabaseFilteredByStatus = createSelector(
+  [hitDatabaseSelector, databaseFilterSettingsSelector],
+  (hitDatabase, { statusFilters }) => {
+    if (statusFilters.isEmpty()) {
+      return hitDatabase;
+    }
+
+    const filterFunction = filterBy(hitDatabase);
+
+    const resultsMaps = statusFilters.reduce(
+      (acc: HitDatabaseMap[], cur: StatusFilterType) =>
+        acc.concat(filterFunction(cur)),
+      []
+    );
+
+    return resultsMaps
+      .reduce(
+        (acc: HitDatabaseMap, cur: HitDatabaseMap) => acc.merge(cur),
+        Map()
+      )
+      .map((el: HitDatabaseEntry) => el.id)
+      .toArray();
+  }
+);
Add selector for filtering HITs by status.
