<template>
  <div class="dialog">
    <div class="center">
      <div class="title">{{title}}</div>
      <div class="text">{{text}}</div>
      <div class="p-3 text-center">
        <button @click="closeDialog()" ref="btn_yes" class="btn bt-sm btn-dark mb-1">YES</button>
        <button @click="closeDialog(false)" ref="btn_no" class="btn bt-sm btn-dark mb-1">NO</button>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent } from 'vue';
import {closeDialog} from 'vue3-promise-dialog'

export default defineComponent({
  props: {
    text: String,
    title: String
  },
  mounted: function () {
    window.addEventListener('keydown', this.onkey)
    this.$refs['btn_yes'].focus()
  },
  beforeUnmount: function () {
    window.removeEventListener('keydown', this.onkey)
  },
  methods: {
    onkey(event) {
      if (event.keyCode == 37) {
        let el = this.$refs['btn_yes']
        if (el) {
          el.focus()
        }
      }
      if (event.keyCode == 39) {
        let el = this.$refs['btn_no']
        if (el) {
          el.focus()
        }
      }
      if (event.keyCode == 27) {
        this.closeDialog(false)
      }
    }
  },
  setup() {
    function returnValue() {
      return true;
    }
    return {
      returnValue,
      closeDialog
    };
  },
});
</script>

<style scoped>
.dialog {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.3);
  z-index: 1000;
}

.center {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: white;
  width: 30%;
  min-width: 400px;
  box-shadow: 5px 5px 5px #6f6f6f;
}

.title {
  background-color: #FFC300;
  padding: 0.5em;
  font-size: 1.5em;
}

.text {
  padding: 0.5em;
  padding-left: 1.5em;
  font-size: 1.2em;
  font-weight: 600;
}

.btn {
  margin: 10px;
  min-width: 100px;
}
</style>
