<script lang="ts">
	import FileText from "$icon/file-text";

	interface Props {
		filename: string;
		contents: string;
		html?: string | null;
	}

	let { filename, contents, html = null }: Props = $props();
</script>

<div
	class="mt-4 w-full overflow-hidden rounded-sm border border-border-default bg-background-default"
>
	<div class="border-b border-border-default px-4 py-2">
		<span class="flex items-center gap-2">
			<FileText class="size-4 text-foreground-subtle" aria-hidden="true" />
			<span class="font-mono text-sm text-foreground-muted">{filename}</span>
		</span>
	</div>
	{#if html}
		<!-- eslint-disable-next-line svelte/no-at-html-tags -- sanitised in $lib/markup -->
		<div class="markup overflow-x-auto px-6 py-4">{@html html}</div>
	{:else}
		<div class="overflow-x-auto px-6 py-4">
			<pre class="font-mono text-sm whitespace-pre text-foreground-default">{contents}</pre>
		</div>
	{/if}
</div>
