<template>
  <transition name="fade">
    <div class="lyf-ui-global-loading" v-show="visible">
      <div class="lyf-ui-global-loading-content" :class="{
        vertical
      }">
        <slot>
          <!-- icon -->
          <div ref="loadingContainer" class="lyf-ui-loading-icon" :style="{
            width: size + 'px',
            height: size + 'px'
          }"></div>
        </slot>
        <div class="lyf-ui-global-loading-message">{{ message }}</div>
      </div>
    </div>
  </transition>
</template>

<script>
import lottie from 'lottie-web'
import white from '@/assets/json/loading_white.json'

export default {
  props: {
    visible: Boolean,
    message: {
      type: String,
      default: '加载中'
    },
    mask: {
      type: Boolean,
      default: true
    },
    size: {
			type: [Number, String],
			default: 24
		},
    vertical: Boolean
  },
  mounted() {
    let animationData = white
    lottie.loadAnimation({
			container: this.$refs.loadingContainer,
			renderer: 'svg',
			animationData
		})
  }
}
</script>

<style scoped>
.lyf-ui-global-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}
.lyf-ui-global-loading .lyf-ui-global-loading-content {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 50%;
  left: 50%;
  padding: var(--space_24);
  border-radius: var(--radius_8);
  background-color: var(--N1_3);
  color: var(--font-color_4);
  font-size: 16px;
  transform: translate3d(-50%, -50%, 0);
}
.lyf-ui-global-loading .lyf-ui-global-loading-content .lyf-ui-global-loading-message {
  margin-left: var(--space_4);
}
.lyf-ui-global-loading .lyf-ui-global-loading-content.vertical {
  flex-direction: column;
}
.lyf-ui-global-loading .lyf-ui-global-loading-content.vertical .lyf-ui-global-loading-message {
  margin-top: var(--space_12);
  margin-left: 0;
}
.lyf-ui-global-loading .lyf-ui-loading-icon {
	display: flex;
	justify-content: center;
	align-items: center;
}
</style>