<script lang="ts">
import { onMount } from 'svelte';
import * as m from '$lib/paraglide/messages.js';

interface LastVisited {
	id: string;
	title: string;
}

let lastVisited = $state<LastVisited | null>(null);

onMount(() => {
	try {
		const raw = localStorage.getItem('familienarchiv.lastVisited');
		if (raw) {
			const parsed = JSON.parse(raw) as LastVisited;
			if (parsed?.id) {
				lastVisited = parsed;
			}
		}
	} catch {
		// ignore malformed JSON
	}
});
</script>

{#if lastVisited}
	<div
		data-testid="resume-strip"
		class="flex items-center gap-2 rounded-sm border border-line bg-surface px-4 py-3 font-sans text-sm"
	>
		<span class="text-ink-2">{m.dashboard_resume_label()}</span>
		<a href="/documents/{lastVisited.id}" class="font-medium text-ink hover:underline">
			{lastVisited.title || m.dashboard_resume_fallback()}
		</a>
	</div>
{/if}
