import Vue from 'vue/dist/vue'
import EventBus from "../util/EventBus";
import EventTypes from "../util/EventTypes";

Vue.component('brick-btn-delete', {
    delimiters: ['<<', '>>'],
    props: [
        'brick',
    ],
    data: function () {
        return {
            isLoading: false,
        };
    },
    methods: {
        beginLoading: function () {
            this.isLoading = true;
        },
        finishLoading: function () {
            this.isLoading = false;
        },
        emit() {
            if (!confirm('Voulez-vous vraiment supprimer ce bloc ?')) {
                return;
            }

            EventBus.emitEvent(EventTypes.BRICK_DELETE, this);
        }
    },
    template: `
      <button
          class="btn brick-action"
          title="Supprimer"
          v-on:click="emit"
      >
        <i :class="{
          'far fa-trash-can': !this.isLoading,
          'fas fa-circle-notch fa-spin': this.isLoading,
        }"></i>
      </button>
    `,
});