<template>
  <div class="play">
    <div class="play__layout">
      <div :class="['play__layout-playground', cssLayoutClass ]">
        <Quote :text="quote" />
        <Sources :sources="sources" :selectable="selectable" />
      </div>
      <div class="play__layout-right-column">
        <PlayerList :players="players" />
        <ConfirmButton v-if="selectable"/>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  computed: {
    cssLayoutClass() {
      if (this.$store.state.game.phase === 'reveal-start') {
        return 'play__layout-playground__flip-out'
      } else if (this.$store.state.game.phase === 'reveal-show-count') {
        return 'play__layout-playground__flip-in'
      }

      return
    },
    gamePhase() {
      return this.$store.state.game.phase
    },
    quote() {
      return this.$store.state.round.quote
    },
    sources() {
      return this.$store.state.round.sources
    },
    players() {
      return this.$store.state.players.players
    },
    selectable() {
      const userId = this.$store.state.engine.user.id
      const selection = this.$store.state.round.selections[userId]

      if (this.$store.state.game.phase != 'select-quote') return false
      if (typeof selection === 'undefined') return true
      return !selection
    },
  },
}
</script>

<style lang="scss">
html,
body,
#__nuxt,
#__layout,
.layout-default,
.page-play {
  height: 100%;
}

.play {
  position: relative;
  width: 100%;
  height: 100%;

  &__layout {
    display: flex;
    width: 100%;
    height: 100%;
    perspective: 1200px;

    &-playground {
      position: relative;
      flex-grow: 1;

      &__flip-out {
        animation: flip-out .5s ease-in-out;
        animation-fill-mode: forwards;
      }

      &__flip-in {
        animation: flip-in .5s linear;
        animation-fill-mode: forwards;
      }
    }

    &-right-column {
      width: 200px;
      margin: 16px 16px 0 0;
    }

  }

}
@keyframes flip-out {
  to   { transform: rotateX(90deg); }
}
@keyframes flip-in {
  0%   { transform: rotateX(90deg); }
  90%  { transform: rotateX(0deg); }
}
</style>
