import Vue from 'vue'
import Vuex from 'vuex'
import _ from 'lodash'
import * as types from './mutationTypes'

Vue.use(Vuex);


const obstacleSets = [
  // level 1
  [
    [.125, .8, 1], [.375, .8, 1], [.625, .8, 1], [.875, .8, 1],
    [.25, .8, -1], [.5, .8, -1], [.75, .8, -1],
  ],
  //level 2
  [
    [.125, .9, -1], [.375, .9, -1], [.625, .9, -1], [.875, .9, -1],
    [.25, .9, 1], [.5, .9, 1], [.75, .9, 1]
  ],
  [
    [.125, .9, -1], [.375, .9, -1], [.625, .9, -1], [.875, .9, -1],
    [.125, .9, 1], [.375, .9, 1], [.75, .9, 1]
  ],
];


let state = {
  waves: [{frequency: 1, amplitude: 100, phase: 0}],
  activeWave: null,
  playSound: false,
  currentObstacleSet: 0,
  obstacleSets
};
state.activeWave = state.waves[0];

export default new Vuex.Store({
  state,
  mutations: {
    [types.ADD_WAVE](state, wave) {
      state.waves.push(wave);
    },
    [types.DELETE_WAVE](state, wave) {
      state.waves = _.filter(state.waves, w => w !== wave);
    },
    [types.CLEAR_WAVES](state) {
      state.waves = [];
    },
    [types.UPDATE_ACTIVE_WAVE](state, wave) {
      state.activeWave = wave
    },
    [types.UPDATE_ACTIVE_WAVE_FREQ](state, freq) {
      state.activeWave.frequency = freq;
    },
    [types.UPDATE_ACTIVE_WAVE_AMP](state, amp) {
      state.activeWave.amplitude = amp;
    },
    [types.UPDATE_ACTIVE_WAVE_PHASE](state, phase) {
      state.activeWave.phase = phase;
    },
    [types.TOGGLE_AUDIO](state) {
      state.playSound = !state.playSound;
    },
    [types.UPDATE_CURRENT_OBSTACLE_SET](state, value) {
      state.currentObstacleSet = value;
    }
  },
  getters: {

  },
  actions: {

  }
});
