<script lang="ts">
	import { compactRelativeTime, formatDate, relativeTime } from "$lib/format";

	interface Props {
		value: string | Date;
		variant?: "compact" | "full";
		class?: string;
	}

	let { value, variant = "compact", class: className }: Props = $props();

	const text = $derived(variant === "compact" ? compactRelativeTime(value) : relativeTime(value));
	const iso = $derived(typeof value === "string" ? value : value.toISOString());
</script>

{#if text}
	<time datetime={iso} title={formatDate(value)} class={className}>{text}</time>
{/if}
