<template>
  <div class="modal">
    <div class="modal-mask">
      <div class="modal-wrapper">
        <div class="modal-container" v-on-clickaway="() => $emit('clickaway')">
          <div class="modal-header">
            <h4>{{ headerText }}</h4>
          </div>
          <div class="modal-body">
            <p>{{ bodyText }}</p>
          </div>
          <div class="modal-footer">
            <button
              v-for="button in buttons"
              @click="buttonClickHandler(button)"
              :class="button.classes"
              class="button"
            >{{ button.text }}</button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { mixin as clickaway } from 'vue-clickaway2';

  import { put } from '../helpers/api.js';

  export default {
    mixins: [ clickaway ],
    props: [
        'bodyText',
        'headerText',
        'buttons'
    ],
    data() {
      return {

      }
    },
    methods: {
      buttonClickHandler(button) {
        if (button.emitString != null) {
          this.buttonEmit(button);
        } else {
          this.buttonCallback(button);
        }
      },

      buttonEmit(button) {
        this.$emit(button.emitString, button.emitPayload);
      },

      buttonCallback(button) {
        button.callback();
      }
    }
  }
</script>
