<script lang="ts">
	import ActivityHistory from '$lib/Tools/ActivityHistory.svelte';
	import { todaysCharacterBirthdays } from '$lib/AniList/character';

	export let data;

	let tool: number;
</script>

<p>
	<select bind:value={tool}>
		<option value={0}>Tools</option>
		<option value={1}>Today's Character Birthdays</option>
		<option value={2}>Activity History Hole Risks</option>
	</select>
</p>

{#if tool === 0}
	Select a tool to continue.
{:else if tool === 2}
	<ActivityHistory user={data.user} />
{:else if tool === 1}
	<ul>
		{#await todaysCharacterBirthdays()}
			<li>Loading ...</li>
		{:then birthdays}
			{#each birthdays as birthday}
				<li>
					<a href={`https://anilist.co/character/${birthday.id}`} target="_blank"
						>{birthday.name.full}</a
					>
				</li>
			{/each}
		{:catch}
			<li>
				<p>
					Characters could not be loaded. You might have been <a
						href="https://en.wikipedia.org/wiki/Rate_limiting"
						target="_blank">rate limited</a
					>.
				</p>
				<p>
					Try again in a few minutes. If the problem persists, please contact
					<a href="https://anilist.co/user/fuwn" target="_blank">@fuwn</a> on AniList.
				</p>
			</li>
		{/await}
	</ul>
{/if}
