export interface RecentLocation { mapId: number x: number y: number zoom?: number label?: string at: number } const STORAGE_KEY = 'hnh-map-recent-locations' const MAX_RECENT = 10 function loadRecent(): RecentLocation[] { if (import.meta.server) return [] try { const raw = localStorage.getItem(STORAGE_KEY) if (!raw) return [] const parsed = JSON.parse(raw) as RecentLocation[] return Array.isArray(parsed) ? parsed.slice(0, MAX_RECENT) : [] } catch { return [] } } function saveRecent(list: RecentLocation[]) { if (import.meta.server) return try { localStorage.setItem(STORAGE_KEY, JSON.stringify(list.slice(0, MAX_RECENT))) } catch (_) {} } export function useRecentLocations() { const recent = ref([]) function refresh() { recent.value = loadRecent() } function push(entry: Omit) { const list = loadRecent() const at = Date.now() const filtered = list.filter( (r) => !(r.mapId === entry.mapId && r.x === entry.x && r.y === entry.y) ) filtered.unshift({ ...entry, at }) saveRecent(filtered) refresh() } function clear() { saveRecent([]) refresh() } onMounted(refresh) return { recent: readonly(recent), refresh, push, clear, } }