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

export const useCitiesStore = defineStore('cities', {
    state: () => ({
        cities: [],
    }),

    getters: {
        // @ts-ignore
        getCities: (state) => state.cities,
    },

    actions: {
        initCities() {
            const citiesCookie = useCookie('cities',{ maxAge: 60 * 60 * 24 * 365 });

            // @ts-ignore
            this.cities = citiesCookie.value || [];
        },


        setCities(cities: any) {
            const citiesCookie = useCookie('cities',{ maxAge: 60 * 60 * 24 * 365 });


            // Set the cities in the cookie with 1 year expiry
            citiesCookie.value = cities;

            // @ts-ignore
            this.cities = cities;
        },
    },
});
