import type { RecentSearch } from './models/search'; export class Settings> { keyBase: string | null; constructor(keyBase: string | null = null) { this.keyBase = keyBase; } private generateKey(id: string | number | symbol): string { const idStr = typeof id === 'string' ? id : String(id); return this.keyBase ? [this.keyBase, `id${idStr}`].join('.') : idStr; } set(id: K, data: T[K]): T[K] | null { const key = this.generateKey(id); try { const encodedData = JSON.stringify(data); localStorage.setItem(key, encodedData); return data; } catch { return null; } } get(id: K): T[K] | null { const key = this.generateKey(id); try { const rawData = localStorage.getItem(key); if (rawData === null) return null; return JSON.parse(rawData) as T[K]; } catch { return null; } } remove(id: K): T[K] | null { const data = this.get(id); if (data !== null) { const key = this.generateKey(id); try { localStorage.removeItem(key); } catch { // ignore if the key is not found } } return data; } } export const pushNotificationsSetting = new Settings< Record >('mastodon_push_notification_data'); export const tagHistory = new Settings>( 'mastodon_tag_history', ); export const bannerSettings = new Settings>( 'mastodon_banner_settings', ); export const searchHistory = new Settings>( 'mastodon_search_history', ); export const playerSettings = new Settings<{ volume: number; muted: boolean }>( 'mastodon_player', ); export const wrapstodonSettings = new Settings< Record >('wrapstodon');