// @ts-ignore
import {defineStore} from 'pinia'
// @ts-ignore
import {useCookie} from '#app'

export const useConfigStore = defineStore('config', {
    state: () => ({
        config: {},
        onBoarding: false
    }),
    actions: {
        async init() {
            const {$api} = useNuxtApp();
            const onBoardingCookie = useCookie('onBoarding'); // Initialize the cookie inside the action
            // @ts-ignore
            if (typeof onBoardingCookie.value === 'undefined') {
                // @ts-ignore
                this.setOnBoarding(false)
            }

            // @ts-ignore
            this.onBoarding = onBoardingCookie.value


            // @ts-ignore
            await $api.post('/config', {}).then((value: { data: { data: null; }; }) => {
                // @ts-ignore
                this.config = value.data.data;
            })
        },
        setOnBoarding(status: Boolean) {
            const onBoardingCookie = useCookie('onBoarding',{ maxAge: 60 * 60 * 24 * 365 }); // Initialize the cookie inside the action

            // @ts-ignore
            this.onBoarding = status
            onBoardingCookie.value = status; // Store the token in cookies
        }
    },
})
