<template>
<div id="app" v-if="model">
  <TopMenu v-bind:user="model.user" />
  <div class="container">
    <router-view></router-view>
  </div>
  <div id="loading" v-if="loading">
    <div id="spinner-wrapper">
      <b-spinner variant="primary" style="width: 3rem; height: 3rem;" label="Loading"></b-spinner>
    </div>
  </div>
  <div class="mt-4">
    <p class="text-center">&mdash;&nbsp; Powered by
      <img src="@/assets/logo-ia2-small.jpg" alt="logo IA2" /> &nbsp;
      <a href="https://www.ia2.inaf.it/" target="_blank">IA2</a> &nbsp;&mdash;
    </p>
  </div>
</div>
</template>

<script>
import TopMenu from './components/TopMenu.vue';
import { mapState } from 'vuex';
import client from 'api-client';

export default {
  name: 'app',
  components: {
    TopMenu
  },
  computed: mapState({
    model: state => state.model,
    input: state => state.input,
    loading: state => state.loading,
    page: state => state.page
  }),
  mounted: function() {
    var self = this;
    document.addEventListener('apiError', function(event) {
      self.$bvToast.toast(event.message.body, {
        title: event.message.title,
        variant: 'danger',
        solid: true
      });
    });
    document.addEventListener('loading', function(event) {
      self.$store.commit('setLoading', event.value);
    });

    // retrieve the initial model
    this.$store.dispatch('loadHomePageModel');

    setInterval(client.keepAlive, 60000);
  }
}
</script>

<style scoped>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#loading {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  background-color: rgba(255, 255, 255, 0.7);
  z-index: 1000;
}

#spinner-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 100%;
}
</style>
