<template>
      <nav>

        <RouterLink to="/">{{ t("Home") }}</RouterLink>

        <RouterLink v-for="link in links" v-model="links" :to="`${link.page.path}`">
            {{ link.Label }}
        </RouterLink>
        <select @change="changeLocale()" v-model="$i18n.locale">
          <option v-for="(lang, i) in $i18n.availableLocales" :key="`Lang${i}`" :value="lang">
            {{ lang }}
          </option>
        </select>
      </nav>
</template>

<style scoped>
nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  line-height: 90px;
  margin: 0;
  padding: 0;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a, nav select {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}
</style>

<script lang="ts">
    import { useFooterLinksStore } from '@/stores/footer-content-pages'
    import {loadDynamicPages} from '@/router'
    import { useI18n } from 'vue-i18n'

    export default {
        name: 'Navigation',
        data () {
            return {
            links: [] as Array<any>,
            error: null as any,
            footerLinksStroe: null as any
            }
        },
        setup(){
          const { t } = useI18n({
            inheritLocale: true
          })
          return{
            t
          }
        },
        async mounted () {
          if(!this.footerLinksStroe){
            this.footerLinksStroe = useFooterLinksStore()
          }
            
            this.links = await this.footerLinksStroe.getLinks(this.$i18n.locale)
        },
        methods:{
          async changeLocale(){
            let locale = this.$i18n.locale
            loadDynamicPages(locale)
            localStorage.setItem('lang',locale)
            if(!this.footerLinksStroe){
              this.footerLinksStroe = useFooterLinksStore()
            }
            this.links = await this.footerLinksStroe.getLinks(locale)
            
          }
        }
        
    }
</script>


