import { defineStore } from 'pinia'
import axios from 'axios'



export const useFooterLinksStore = defineStore('footerLinks',{
  state: () => ({ 
                token: "28f1084766b4010f8a295faf9fdbf83bc35b48fd0c678c09468e503a1ac474b49b03c5c8d2fbb98e1876427ace5f9d58180e3c79afa6d172c97738056e28c7adecff2bb9dfdac40fe6716c743a437b70dbaa8924262b3fa5d5b50258fcf6a163ada089cc5c76b34b3bcd4ec148594b3db5f12888c8bca941898b8ae542d923e5",
                locale:  "" as String,
                links: [] 
              }),
   
   actions: {
    async getLinks(locale:String){
       if (this.locale != locale){
        this.locale = locale
        await this.fetchLinks()
       }
      return this.links

    },
    setLocale(locale:String){
        this.locale = locale
        this.fetchLinks()
    },

      async fetchLinks(){
            const response = await axios.get('https://strapi.kornblum.one/api/footer-content-pages?populate=page&locale='+this.locale, {
            headers: {
                Authorization: "Bearer "+this.token,
            },
            })
            this.links = response.data.data
        },
    }
 })