<script lang="ts">
	import { onMount } from 'svelte';
	import AnimeList from '$lib/List/Anime/DueAnimeList.svelte';
	import MangaListTemplate from '$lib/List/Manga/MangaListTemplate.svelte';
	import UpcomingAnimeList from '$lib/List/Anime/UpcomingAnimeList.svelte';
	import userIdentity from '$stores/identity.js';
	import settings from '$stores/settings';
	import ListTitle from '$lib/List/ListTitle.svelte';
	import HeadTitle from '$lib/Home/HeadTitle.svelte';
	import LastActivity from '$lib/Home/LastActivity.svelte';
	import { createHeightObserver } from '$lib/Utility/html.js';

	export let data;

	onMount(createHeightObserver);
</script>

<HeadTitle />

<LastActivity user={data.user} />

<div
	id="list-container"
	style={`column-width: 300px; column-count: ${
		Number(!$settings.disableAnime) +
		Number(!$settings.disableManga) +
		Number(!$settings.disableUpcomingAnime) -
		Number(!$settings.disableUpcomingAnime && !$settings.disableAnime && !$settings.disableManga)
	};`}
>
	{#if data.user === undefined}
		<div class="card">Please log in to view due media.</div>
	{:else}
		{#if !$settings.disableUpcomingAnime}
			<details open={!$settings.displayUpcomingAnimeCollapsed} class="list">
				{#if $userIdentity.id != -1}
					<UpcomingAnimeList user={data.user} identity={$userIdentity} />
				{:else}
					<ListTitle custom="Upcoming Episodes" />

					<ul><li>Loading user identity ... 50%</li></ul>
				{/if}
			</details>

			{#if !$settings.disableAnime || !$settings.disableManga}
				<p />
			{/if}
		{/if}

		{#if !$settings.disableAnime}
			<details open={!$settings.displayAnimeCollapsed} class="list">
				{#if $userIdentity.id != -1}
					<AnimeList user={data.user} identity={$userIdentity} />
				{:else}
					<ListTitle anime />

					<ul><li>Loading user identity ... 50%</li></ul>
				{/if}
			</details>

			{#if !$settings.disableManga}
				<p />
			{/if}
		{/if}

		{#if !$settings.disableManga}
			<details open={!$settings.displayMangaCollapsed} class="list">
				{#if $userIdentity.id != -1}
					<MangaListTemplate
						user={data.user}
						identity={$userIdentity}
						displayUnresolved={$settings.displayUnresolved}
						due={true}
					/>
				{:else}
					<ListTitle />

					<ul><li>Loading 0% ...</li></ul>
				{/if}
			</details>
		{/if}

		{#if $settings.disableUpcomingAnime && $settings.disableAnime && $settings.disableManga}
			<video src="https://video.twimg.com/tweet_video/Do_eDPnX0AAKV9f.mp4" autoplay loop>
				<track kind="captions" />
			</video>
		{/if}
	{/if}
</div>

<style>
	.list {
		overflow-y: auto;
		break-inside: avoid;
		/* max-height: 80vh; */
		overflow-y: auto;
		page-break-inside: avoid;
	}
</style>
