<template>
  <div>
    <div class="row">
      <div class="col-12 col-md-8 offset-sm-2 col-lg-6 offset-md-3">
        <button class="btn btn-danger" @click="stopGame">
          Stop game
        </button>
        <input type="text" v-model="chatMessage" @keydown.enter="sendChat" />
        <button
          class="btn btn-primary"
          @click="sendChat"
          :disabled="chatMessage === ''"
        >
          Chat
        </button>
      </div>
    </div>
    <hr />
    <component :is="gameStepDisplay" :select-heroes="true"></component>
  </div>
</template>

<script>
import { mapGetters } from 'vuex';
import { socketService } from '../main';
import HeroesDisplay from '../common/heroes-display/HeroesDisplay';
import OnlineWait from './components/OnlineWait';
import GameBoard from './components/GameBoard';
export default {
  components: {
    HeroesDisplay,
    OnlineWait,
    GameBoard
  },
  data() {
    return {
      chatMessage: ''
    };
  },
  computed: {
    ...mapGetters({
      gameState: 'game/state'
    }),
    gameStepDisplay() {
      let componentToDisplay = '';
      switch (this.gameState) {
        case null:
        case '':
        case '0_INIT':
          componentToDisplay = 'online-wait';
          break;
        case '1_SELECT_FACTION':
        case '1_SELECT_DRAFT':
        case '1_SELECT_TOURNAMENT':
          componentToDisplay = 'heroes-display';
          break;
        case '2_CHANGE_UP_TO_3_CARDS':
          componentToDisplay = 'game-board';
          break;
        default:
          componentToDisplay = 'online-wait';
          break;
      }
      return componentToDisplay;
    }
  },
  methods: {
    stopGame() {
      this.$store.dispatch('stopGame');
      this.$store.dispatch('game/resetGameState');
    },
    sendChat() {
      socketService.chat(this.chatMessage);
      this.chatMessage = '';
    }
  },
  created() {}
};
</script>

<style></style>
