<template>
  <div id="app">
    <div id="nav">
      <router-link to="/">Home</router-link> |
      <router-link to="/about">About</router-link> |
      <router-link to="/login">Login</router-link> |
      <router-link to="/profile">Profile</router-link> |
        <!-- Example split danger button -->
        <div class="btn-group">
            <button type="button" onclick="location.href='/admin'" class="btn btn-danger">Admin</button>
            <button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span class="sr-only">Toggle Dropdown</span>
            </button>
            <div class="dropdown-menu">
                <router-link class="dropdown-item" :to="{ name: 'admin.user' }">{{ $t('user') }}</router-link>
                <router-link class="dropdown-item" :to="{ name: 'admin.group' }">{{ $t('group') }}</router-link>
                <a class="dropdown-item" href="#">Something else here</a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="#">Separated link</a>
            </div>
        </div> |
      <span>({{tokenValidity}})</span> |
      <span>({{refreshTokenValidity}})</span>
    </div>
    <router-view/>
  </div>

</template>

<script>
  import {getRemainingJwtValiditySeconds} from "@/utils";

  export default {
    data () {
      return {
        tokenValidity: -1,
        refreshTokenValidity: -1,
      };
    },
    methods: {
    },
    mounted () {

      this.$nextTick(() =>{
        window.setInterval(() => {
          this.$log.debug(getRemainingJwtValiditySeconds(this.$store.state.access_token));
          this.tokenValidity = getRemainingJwtValiditySeconds(this.$store.state.access_token);
          this.refreshTokenValidity = getRemainingJwtValiditySeconds(this.$store.state.refresh_token);
          this.$log.debug(this.$store.state);
        }, 1000);
      });


    },
  }
</script>

<style lang="scss">
  @import '../node_modules/bootstrap/scss/bootstrap.scss';
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
#nav {
  padding: 30px;
  a {
    font-weight: bold;
    color: #2c3e50;
    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
