import { getCookie, setCookie } from '../utils/cookies.js'

export const settings = {
	namespaced: true,
	state: {
		filters: {
			listened: true,
			listening: true,
			unlistened: true,
		},
	},
	mutations: {
		filters: (state, filters) => {
			state.filters = { ...state.filters, ...filters }
			setCookie('repod.filters', JSON.stringify(state.filters), 365)
		},
	},
	actions: {
		fetch: (context) => {
			try {
				const filters = getCookie('repod.filters')
				context.commit('filters', JSON.parse(filters))
			} catch (e) {
				// nothing
			}
		},
	},
}
