<template>
  <button @mouseover="describe" class="action-button" @click="execute">
    <div class="action-title">{{ action.name }}</div>
    <div class="action-desc">{{ action.desc }}</div>
  </button>
</template>

<script lang="ts">

import { Component, Prop, Vue, Watch, Emit } from 'vue-property-decorator'
import { Action, GroupAction } from '@/game/combat'
import { Creature } from '@/game/creature'

@Component({})
export default class ActionButton extends Vue {
  @Prop()
  action!: Action

  @Prop()
  user!: Creature

  @Prop()
  target!: Creature

  @Prop()
  combatants!: Array<Creature>

  @Emit("execute")
  execute () {
    if ((this.action as GroupAction).executeGroup !== undefined) {
      const action = (this.action as GroupAction)
      this.$emit('executed', (this.action as GroupAction).executeGroup(this.user, action.allowedGroup(this.user, this.combatants)))
    } else {
      this.$emit('executed', this.user.executeAction(this.action, this.target))
    }
  }

  @Emit("describe")
  describe () {
    if ((this.action as GroupAction).describeGroup !== undefined) {
      const action = (this.action as GroupAction)
      this.$emit('described', action.describeGroup(this.user, action.allowedGroup(this.user, this.combatants)))
    } else {
      this.$emit('described', this.action.describe(this.user, this.target))
    }
  }
}

</script>

<style scoped>

.action-button {
  width: 100%;
  padding: 4pt;
  flex: 0 1;
  background: #333;
  border-color: #666;
  border-style: outset;
  user-select: none;
}

.action-button:hover {
  background: #555;
}

.action-title {
  font-size: 125%;
  color: #eee;
}

.action-desc {
  color: #ccc;
}

</style>
