<script>
	import { marked } from 'marked';
	import DOMPurify from 'dompurify';

	export let at;
	export let body;

	$: renderedBody = DOMPurify.sanitize(marked.parse(body, { breaks: true }));

	let scroll = (message) => {
		message.scrollIntoView();
	};
</script>

<div class="message relative">
	<span class="timestamp chip variant-soft absolute top-0 right-0">{at}</span>
	<section use:scroll class="py-1 message-body">
		<!-- eslint-disable-next-line svelte/no-at-html-tags -->
		{@html renderedBody}
	</section>
</div>

<style>
	.message .timestamp {
		display: none;
	}
	.message:hover .timestamp {
		display: flex;
	}
	.message-body:empty:after {
		content: '.';
		visibility: hidden;
	}
</style>
