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

Vue.component('brick-btn-template', {
    delimiters: ['<<', '>>'],
    props: [
        'brick',
    ],
    data: function () {
        return {
            isLoading: false,
        };
    },
    methods: {
        beginLoading: function () {
            this.isLoading = true;
        },
        finishLoading: function () {
            this.isLoading = false;
        },
        emit() {
            EventBus.emitEvent(EventTypes.BRICK_TEMPLATE_CREATE, this);
        }
    },
    template: `
      <button
          class="btn brick-action brick-template"
          title="Sauvegarder en tant que template"
          v-on:click="emit"
      >
        <i :class="{
          'far fa-floppy-disk': !this.isLoading,
          'fas fa-circle-notch fa-spin': this.isLoading,
        }"></i>
      </button>
    `,
});