<script lang="ts">
	// import { tick, onDestroy } from 'svelte';
	import Game from '$components/Game.svelte';

	export let data;
	console.log(`Page data: ${JSON.stringify(data)}`);
	let collectionItems = data?.collection || [];
	console.log('collectionItems', collectionItems);

	// async function handleNextPageEvent(event: CustomEvent) {
	// 	if (+event?.detail?.page === page + 1) {
	// 		page += 1;
	// 	}
	// 	await tick();
	// }

	// async function handlePreviousPageEvent(event: CustomEvent) {
	// 	if (+event?.detail?.page === page - 1) {
	// 		page -= 1;
	// 	}
	// 	await tick();
	// }

	// async function handlePerPageEvent(event: CustomEvent) {
	// 	page = 1;
	// 	pageSize = event.detail.pageSize;
	// 	await tick();
	// }
</script>

<svelte:head>
	<title>Your Collection | Bored Game</title>
</svelte:head>

<h1>Your Collection</h1>
<!-- <input type="text" id="search" name="search" placeholder="Search Your Collection" bind:value={$searchStore.search} /> -->

<div class="games">
	<div class="games-list">
		{#if collectionItems.length === 0}
			<h2>No games in your collection</h2>
		{:else}
			{#each collectionItems as game (game.game_id)}
				<Game {game} />
			{/each}
		{/if}
	</div>
	<!-- {#if $collectionStore.length !== 0}
		<Pagination
			{pageSize}
			{page}
			{totalItems}
			forwardText="Next"
			backwardText="Prev"
			pageSizes={[10, 25, 50, 100]}
			on:nextPageEvent={handleNextPageEvent}
			on:previousPageEvent={handlePreviousPageEvent}
			on:perPageEvent={handlePerPageEvent}
		/>
	{/if} -->
</div>

<style lang="postcss">
	h1 {
		margin: 1.5rem 0rem;
		width: 100%;
	}

	.games {
		margin: 2rem 0rem;
	}

	.games-list {
		display: grid;
		grid-template-columns: repeat(3, minmax(200px, 1fr));
		gap: 2rem;

		@media (max-width: 800px) {
			grid-template-columns: 1fr 1fr;
		}

		@media (max-width: 550px) {
			grid-template-columns: 1fr;
		}
	}
</style>
