import Vue from 'vue'
import Vuex from 'vuex'

import SekcieStore from './modules/sekcie'
import KategorieStore from './modules/kategorie'
import PouzivateliaStore from './modules/pouzivatelia'
import UcebneMaterialyStore from './modules/ucebneMaterialy'

import nastaveniaState from './modules/nastavenia/state'
import nastaveniaMutations from './modules/nastavenia/mutations'

Vue.use(Vuex)

const API_URL = process.env.ROOT_API
const sekcieStore = new SekcieStore(API_URL)
const kategorieStore = new KategorieStore(API_URL)
const pouzivateliaStore = new PouzivateliaStore(API_URL)
const ucebneMaterialyStore = new UcebneMaterialyStore(API_URL)

const store = new Vuex.Store({
  modules: {
    nastavenia: Object.assign({namespaced: true}, {
      state: nastaveniaState,
      mutations: nastaveniaMutations,
    }),
    kniznica: {
      namespaced: true,
      modules: {
        sekcie: Object.assign({namespaced: true}, sekcieStore.getStore()),
        kategorie: Object.assign({namespaced: true}, kategorieStore.getStore()),
        ucebneMaterialy: Object.assign({namespaced: true}, ucebneMaterialyStore.getStore()),
      },
    },
    pouzivatelia: Object.assign({namespaced: true}, pouzivateliaStore.getStore())
  }
})

export { store }
