<script lang="ts">
	import { page } from '$app/stores';
	import { ComicFilterContext, cycleBooleanFilter, getFilterContext } from '$lib/Filter';
	import { accelerator } from '$lib/Shortcuts';
	import Star from '$lib/icons/Star.svelte';

	const filter = getFilterContext<ComicFilterContext>();
	$: favourite = $filter.include.controls.favourite.value;

	const toggle = () => {
		$filter.include.controls.favourite.value = cycleBooleanFilter(favourite, false);
		$filter.apply($page.url.searchParams);
	};
</script>

<button
	class:toggled={favourite}
	class="btn-slate"
	title="Filter favourites"
	on:click={toggle}
	use:accelerator={'f'}
>
	<Star {favourite} />
</button>
