<template>
  <Header :searchInput="$store.searchInput" />
  <div class="main-body"><router-view /></div>
  <Footer />
</template>

<script>
import Header from './components/header.vue'
import Footer from './components/footer.vue'

import fetch from '@/lib/fetch.js'

export default {
  components: { Header, Footer },

  mounted() {
    var user = localStorage.getItem('user')
    var checked = sessionStorage.getItem('session_checked')

    if (user) {
      if (checked) {
        return (this.$store.user = JSON.parse(user))
      }
      fetch('/login/check')
        .then(r => {
          localStorage.setItem('token', r.data.token)
          sessionStorage.setItem('session_checked', 1)
          this.$store.user = JSON.parse(user)
        })
        .catch(r => {
          localStorage.removeItem('token')
          localStorage.removeItem('user')
        })
    }
  }
}
</script>

<style lang="scss">
::-webkit-scrollbar {
  width: 6px;
  background: var(--color-plain-3);
}
::-webkit-scrollbar-thumb {
  background: var(--color-dark-a);

  &:hover {
    background: var(--color-dark-1);
  }
}
body {
  line-height: 1.5;
  font-size: 14px;
  color: var(--color-dark-1);
}
a {
  color: inherit;
  text-decoration: none;
}
.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
}

.main-body {
  flex: 1;
}
</style>
