/*
 Rookeries client - redux application store

 @copyright (c) Copyright 2013-2017 Dorian Pula
 @license AGPL v3
 @author Dorian Pula [dorian.pula@amber-penguin-software.ca]
 */

import {createStore, applyMiddleware, compose} from 'redux';
import {createLogger} from 'redux-logger';
import thunkMiddleware from 'redux-thunk';

import {reducer} from './reducers';


function injectDevTools() {

  // Inject the dev tools if window used.
  if (process.env.BROWSER_ENV) {
    if (typeof window === 'object' && typeof window.devToolsExtension !== 'undefined') {
      return window.devToolsExtension()
    }
  }

  return (f) => {return f;}
}


export default createStore(
  reducer,
  compose(
    applyMiddleware(
      ...[thunkMiddleware].concat(
        (process.env.BROWSER_ENV) ? [createLogger()] : [])
    ),
    injectDevTools()
  )
);
