<template>
  <nav>
    <ul>
      <li v-for="item in menu" :key="item.text">
        <a href="#">{{ $t(`navigation.${item.text}`) }}</a>
        <ul v-if="item.submenu">
          <li v-for="subitem in item.submenu" :key="subitem.text">
            <a href="#">{{ $t(`navigation.${subitem.text}`) }}</a>
          </li>
        </ul>
      </li>
    </ul>
    <div class="right-block">
      <button @click="accessMailbox">{{ $t('navigation.mailbox') }}</button>
      <button @click="logout">{{ $t('navigation.logout') }}</button>
    </div>
  </nav>
</template>

<script>
import { mapGetters } from 'vuex';

export default {
  name: 'AppNavigation',
  computed: {
    ...mapGetters('menu'),
  },
  created() {
    if(this.$store.getters.hashedId) {
      this.$store.dispatch('loadMenu');
    }
  },
  methods: {
    accessMailbox() {
      alert('Accessing Mailbox...');
    },
    logout() {
      this.$store.dispatch('logout');
    }
  }
};
</script>

<style lang="scss" scoped>
@import '../assets/styles.scss';

nav,
nav > ul{
  display: flex;
  justify-content: space-between;
  background-color: #F9A22C;
  color: #000000;
  padding: 10px;
  flex-direction: row;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  margin: 5px 0;
}
a {
  color: #000000;
  text-decoration: none;
}
.right-block {
  display: flex;
  gap: 10px;
}
button {
  background-color: #495057;
  color: white;
  border: none;
  padding: 5px 10px;
  cursor: pointer;
}
button:hover {
  background-color: #6c757d;
}
</style>
