<script lang="ts">
	import { linkify, linkHref } from '$lib/format';

	let { text }: { text: string | undefined | null } = $props();
	const value = $derived(text ?? '');
	const tokens = $derived(linkify(value));
</script>

{#each tokens as tok, i (i)}
	{#if tok.kind === 'url'}
		<a href={linkHref(tok.content)} target="_blank" rel="noreferrer">{tok.content}</a>
	{:else}
		{tok.content}
	{/if}
{/each}
