<template>
    <div id="overlayWhite" v-show="show">
        <div id="spinner">
            <div class="loader">
                <span :class="`item-${i}`" v-for="i in 7" :key="i"></span>
            </div>
            <div class="message" v-html="message"></div>
        </div>
    </div>
</template>

<script>
/**
* This component creates the main application loader animation.
* Triggered using global event <i>showLoad, hideLoad, updateLoad </i>
*/
export default {
    name: 'MainLoader',
    data () {
        return {
            show: false,
            message: ''
        }
    },
    mounted () {
        this.$events.on('showLoad', (d) => {
            this.message = d
            this.show = true
        })
        this.$events.on('hideLoad', (d) => {
            this.show = false
        })
        this.$events.on('updateLoad', (d) => {
            this.message = d
            if (!this.show) {
                this.show = true
            }
        })
    }
}
</script>
