import type {Moment} from 'moment'
import type {ProcessedMealType} from '../types'
import type {FilterType, PickerType} from '@frogpond/filter'
import {findMeal} from './find-menu'

export function chooseMeal(
	meals: ProcessedMealType[],
	filters: FilterType[],
	now: Moment,
): ProcessedMealType {
	let mealChooserFilter: FilterType | undefined = filters.find(
		(f) => f.type === 'picker' && f.spec.title === "Today's Menus",
	) as PickerType | undefined

	let selectedMeal: ProcessedMealType | undefined = meals[0]
	if (
		mealChooserFilter &&
		mealChooserFilter.spec.selected &&
		mealChooserFilter.spec.selected.label
	) {
		const label = mealChooserFilter.spec.selected.label
		selectedMeal = meals.find((meal) => meal.label === label)
	} else {
		selectedMeal = findMeal(meals, now)
	}

	if (!selectedMeal) {
		selectedMeal = {
			label: '',
			stations: [],
			starttime: '0:00',
			endtime: '0:00',
		}
	}

	return selectedMeal
}

import type {Moment} from 'moment'
import type {ProcessedMealType} from '../types'
import type {FilterType} from '@frogpond/filter'
import {findMeal} from './find-menu'

export function chooseMeal(
	meals: ProcessedMealType[],
	filters: FilterType[],
	now: Moment,
): ProcessedMealType {
	const mealChooserFilter: FilterType | undefined = filters.find(
		(f) => f.type === 'picker' && f.spec.title === "Today's Menus",
	)

	let selectedMeal = meals[0]
	if (
		mealChooserFilter &&
		mealChooserFilter.spec.selected &&
		mealChooserFilter.spec.selected.label
	) {
		const label = mealChooserFilter.spec.selected.label
		selectedMeal = meals.find((meal) => meal.label === label)
	} else {
		selectedMeal = findMeal(meals, now)
	}

	if (!selectedMeal) {
		selectedMeal = {
			label: '',
			stations: [],
			starttime: '0:00',
			endtime: '0:00',
		}
	}

	return selectedMeal
}

--- 
+++ 
@@ -1,6 +1,6 @@
 import type {Moment} from 'moment'
 import type {ProcessedMealType} from '../types'
-import type {FilterType} from '@frogpond/filter'
+import type {FilterType, PickerType} from '@frogpond/filter'
 import {findMeal} from './find-menu'
 
 export function chooseMeal(
@@ -8,11 +8,11 @@
 	filters: FilterType[],
 	now: Moment,
 ): ProcessedMealType {
-	const mealChooserFilter: FilterType | undefined = filters.find(
+	let mealChooserFilter: FilterType | undefined = filters.find(
 		(f) => f.type === 'picker' && f.spec.title === "Today's Menus",
-	)
+	) as PickerType | undefined
 
-	let selectedMeal = meals[0]
+	let selectedMeal: ProcessedMealType | undefined = meals[0]
 	if (
 		mealChooserFilter &&
 		mealChooserFilter.spec.selected &&
m/food-menu: Add some type annotations to help TypeScript figure it out

Signed-off-by: Kristofer Rye <1ed31cfd0b53bc3d1689a6fee6dbfc9507dffd22@gmail.com>
