import { type Writable, writable } from 'svelte/store'
import { type AggregatedFood, FoodService } from '$lib/database/food'


async function createStore(): Promise<Writable<AggregatedFood[]>> {
	let [foods, err] = await FoodService.GetMonthly()
	if (err) {
		foods = []
		console.error(err)
	}

	const { subscribe, update, set } = writable(foods)
	return {
		subscribe,
		update,
		set
	}
}

export const monthlyFoodStore = await createStore()
