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


async function createStore(): Promise<Writable<Food[]>> {
	const foods = await FoodService.GetRecent()
	const { subscribe, update, set } = writable(foods)
	return {
		subscribe,
		update,
		set,
		// @ts-ignore
		refresh: async () => {
			const foods = await FoodService.GetRecent()
			set(foods)
		}
	}
}

export const foodStore = await createStore()
