<template>
  <transition name="xb-loading-fade" @after-leave="handleAfterLeave">
    <div
      v-show="visible"
      class="xb-loading-mask"
      :style="{ backgroundColor: background || '' }"
      :class="[customClass, { 'is-fullscreen': fullscreen }]">
      <div class="xb-loading-spinner">
        <!-- <svg v-if="!spinner" class="circular" viewBox="25 25 50 50">
          <circle class="path" cx="50" cy="50" r="20" fill="none"/>
        </svg> -->
        <div v-if="!spinner" class="xb-loading-inner">
					<div class="xb-loading-container">
						<div class="xb-loading--ball">
              <div v-for="index in 8" :key="index"></div>
						</div>
					</div>
				</div>
        <i v-else :class="[spinner, 'xb_icon_loading']"></i>
        <p v-if="text" class="xb-loading-text">{{ text }}</p>
      </div>
    </div>
  </transition>
</template>

<script>
  export default {
    data() {
      return {
        text: null,
        spinner: null,
        background: null,
        fullscreen: true,
        visible: false,
        customClass: ''
      };
    },

    methods: {
      handleAfterLeave() {
        this.$emit('after-leave');
      },
      setText(text) {
        this.text = text;
      }
    }
  };
</script>
