<script lang="ts">
	import type { HoverCoverResponse } from './hoverCover';

	export let options: HoverCoverResponse;
	export let width = 250;
</script>

{#if options.hovering}
	<img
		class="hover-image show card card-small"
		src={options.media
			? options.media.coverImage.extraLarge
			: `https://subsplease.org${options.item?.image_url}`}
		alt="Media Cover"
		loading="lazy"
		style={`width: ${width}px; ${options.style}`}
	/>
{/if}

<style lang="scss">
	$coverTransitionTime: 200ms;

	.hover-image {
		position: fixed;
		height: auto;
		display: none;
		border-radius: 8px;
		transition: opacity $coverTransitionTime ease-in-out, top 0.3s ease, left 0.3s ease;
	}

	.show {
		display: block;
	}

	.hover-image {
		animation: dropIn $coverTransitionTime ease-in-out;
	}

	@keyframes dropIn {
		0% {
			opacity: 0;
			transform: translateY(-1rem);
		}

		100% {
			opacity: 1;
			transform: translateY(0);
		}
	}
</style>
