<script>
	import { ACDBBirthdays } from '$lib/ACDB';
	import Error from '$lib/Error.svelte';

	let date = new Date();
</script>

{#await ACDBBirthdays(date.getMonth() + 1, date.getDate())}
	<p>Loading ...</p>
{:then birthdays}
	<p>
		This tool does not use AniList's API, so it will have more characters than AniList, but also
		some unexpected characters which may not be present in AniList.
	</p>

	<div id="characters">
		{#each birthdays as birthday}
			<div>
				<a
					href={`https://anilist.co/search/characters?search=${encodeURIComponent(
						birthday.name
					).replace(/%20/g, '+')}`}
					target="_blank"
				>
					{birthday.name}
					<img src={birthday.character_image} alt="Character (Large)" class="character-image" />
				</a>
			</div>
		{/each}
	</div>
{:catch}
	<Error type="Character" />
{/await}

<style>
	#characters {
		display: grid;
		grid-template-columns: repeat(auto-fill, minmax(8%, 1fr));
		grid-gap: 0.25%;
		grid-row-gap: 1rem;
	}
</style>
