<template>
  <div>
    <vue-progress-bar></vue-progress-bar>
    <app-navbar></app-navbar>
    <section id="app" class="">
      <div class="container">
        <router-view v-if="!hasError"></router-view>
        <div v-else>
          <h1>Error!</h1>
          <p>{{error}}</p>
        </div>
      </div>
    </section>
  </div>
</template>

<script>

  import { mapMutations, mapState } from "vuex";
  import api from "../lib/Api";

  export default {
    data() {
      return {
        api: api
      };
    },
    computed: {
      ...mapState({
        hasError: state => state.error !== null,
        error: state => state.error,
        authChecked: state => state.authChecked
      })
    },

    watch: {
      isLoading(val) {
        if (val) {
          this.$Progress.start();
        } else {
          this.$Progress.finish();
        }
      }
    },

    created() {
      if (this.user === null && this.authChecked === false) {
        this.checkAuthentication();
        
      }
    },

    components: {
    }
  }

</script>