// @flow

import {getTermInfo} from '../../../../lib/storage'
import {parseTerm} from '../../../../lib/course-search/parse-term'
import type {FilterType} from '../../../components/filter'

export async function buildFilters(): Promise<FilterType[]> {
	const terms = await getTermInfo()
	const allTerms = terms.map(term => ({
		title: term.term,
		label: parseTerm(term.term.toString()),
	}))

	return [
		{
			type: 'toggle',
			key: 'status',
			enabled: false,
			spec: {
				label: 'Only Show Open Courses',
				caption:
					'Allows you to either see only courses that are open, or all courses.',
			},
			apply: {
				key: 'status',
				trueEquivalent: 'O',
			},
		},
		{
			type: 'toggle',
			key: 'type',
			enabled: false,
			spec: {
				label: 'Show Labs Only',
				caption: 'Allows you to only see labs.',
			},
			apply: {
				key: 'type',
				trueEquivalent: 'Lab',
			},
		},
		{
			type: 'list',
			key: 'term',
			enabled: false,
			spec: {
				title: 'Terms',
				options: allTerms,
				mode: 'OR',
				selected: allTerms,
				displayTitle: false,
			},
			apply: {
				key: 'term',
			},
		},
	]
}

@@ -180,16 +180,70 @@
 /filter'
+%0Aimport %7BloadGEs%7D from '../../../../lib/course-search'
 %0A%0Aexport
@@ -440,16 +440,97 @@
 ,%0A%09%7D))%0A%0A
+%09const ges = await loadGEs()%0A%09const allGEs = ges.map(ge =%3E (%7B%0A%09%09title: ge,%0A%09%7D))%0A%0A
 %09return 
@@ -1239,13 +1239,251 @@
 %7D,%0A%09%09%7D,%0A
+%09%09%7B%0A%09%09%09type: 'list',%0A%09%09%09key: 'gereqs',%0A%09%09%09enabled: false,%0A%09%09%09spec: %7B%0A%09%09%09%09title: 'GEs',%0A%09%09%09%09showImages: false,%0A%09%09%09%09options: allGEs,%0A%09%09%09%09mode: 'AND',%0A%09%09%09%09selected: %5B%5D,%0A%09%09%09%09displayTitle: true,%0A%09%09%09%7D,%0A%09%09%09apply: %7B%0A%09%09%09%09key: 'gereqs',%0A%09%09%09%7D,%0A%09%09%7D,%0A
 %09%5D%0A%7D%0A

add ge filter