<!-- The /assignments index page gives an overview of assignments -->

<script lang="ts">
	import { canBeFinished } from "$lib/common/assignments";
	import type { PageProps } from "./$types";

	const { data }: PageProps = $props();
	const unfinishedAssignments = $derived(data.assignments.filter(canBeFinished));
	const finishedAssignments = $derived(data.assignments.filter((a) => !canBeFinished(a)));
</script>

<h1>{data.user.firstName}s opgaver</h1>

<h2>Kommende opgaver</h2>
<ol>
	{#each unfinishedAssignments as assignment}
		<li>
			<span>{assignment.date}</span>
			<a href={`/assignments/${assignment.id}`}>Mere info</a>
		</li>
	{/each}
</ol>

<h2>Færdiggjorte opgaver</h2>
<ol>
	{#each finishedAssignments as assignment}
		<li>
			<span>{assignment.date}</span>
			<a href={`/assignments/${assignment.id}`}>Mere info</a>
		</li>
	{/each}
</ol>
