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

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

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

<button
	type="button"
	class:toggled={organized !== undefined}
	class="btn-slate"
	title="Filter organized"
	on:click={toggle}
	use:accelerator={'o'}
>
	<Organized tristate {organized} />
</button>
