import createReducer from '../utils/create-reducer'
import { SELECT_CORPUS } from '../actions/corpora'
import { FETCH_CORPORA_SUCCESS } from '../actions/servers'
import { FETCH_CORPUS_STATUS_SUCCESS } from '../actions/corpora'

const initialState = {
  // TODO: transform it in a array here?
  list: {},
  selected: null,
  status: null // status of selected corpus
}

export default createReducer(initialState, {
  [FETCH_CORPORA_SUCCESS]: (state, { corpora }) => {
    return {
      ...state,
      list: {...corpora}
    }
  },

  [FETCH_CORPUS_STATUS_SUCCESS]: (state, { corpus, status }) => {
    return {
      ...state,
      selected: corpus,
      status
    }
  },

  [SELECT_CORPUS]: (state, { corpus }) => {
    return {
      ...state,
      selected: corpus
    }
  }
})

@@ -458,37 +458,23 @@
 a %7D) =%3E 
-%7B%0A    return 
+(
 %7B%0A    
- 
- 
 ...state
@@ -471,26 +471,24 @@
   ...state,%0A
-  
     list: %7B.
@@ -498,25 +498,20 @@
 orpora%7D%0A
-  
   %7D
-%0A  %7D
+)
 ,%0A%0A  %5BFE
@@ -569,37 +569,23 @@
 s %7D) =%3E 
-%7B%0A    return 
+(
 %7B%0A    
-  
 ...state
@@ -578,34 +578,32 @@
 %7B%0A    ...state,%0A
-  
     selected: co
@@ -612,18 +612,16 @@
 us,%0A    
- 
- 
 status%0A 
@@ -621,23 +621,18 @@
 tatus%0A  
-  %7D%0A  
 %7D
+)
 ,%0A%0A  %5BSE
@@ -672,25 +672,11 @@
  =%3E 
+(
 %7B%0A
-    return %7B%0A  
     
@@ -689,18 +689,16 @@
 te,%0A    
-  
 selected
@@ -712,15 +712,10 @@
 s%0A  
-  %7D%0A  
 %7D
+)
 %0A%7D)%0A

simplify return values of the corpora reducers