<script lang="ts">
	import type { MutationWith } from '$gql/Utils';
	import Star from '$lib/icons/Star.svelte';
	import { getSelectionContext } from '$lib/selection/Selection.svelte';
	import { toastFinally } from '$lib/Toasts';
	import { getContextClient } from '@urql/svelte';

	const client = getContextClient();
	const selection = getSelectionContext();

	let { mutation }: { mutation: MutationWith<{ favourite: boolean }> } = $props();

	function mutate(favourite: boolean) {
		mutation(client, { ids: selection.ids, input: { favourite } }).catch(toastFinally);
	}
</script>

<button type="button" class="btn-slate justify-start gap-1" onclick={() => mutate(true)}>
	<Star favourite={true} />
	<span>Favourite</span>
</button>
<button type="button" class="btn-slate justify-start gap-1" onclick={() => mutate(false)}>
	<Star favourite={false} />
	<span>Unfavourite</span>
</button>
