import AsyncStorage from '@react-native-async-storage/async-storage' const KEY = 'anisav:progress' interface ProgressEntry { time: number is_watched: boolean } async function readAll(): Promise> { try { const raw = await AsyncStorage.getItem(KEY) return raw ? JSON.parse(raw) : {} } catch { return {} } } async function writeAll(data: Record): Promise { await AsyncStorage.setItem(KEY, JSON.stringify(data)) } export async function getLocalProgress(episodeId: string): Promise { return (await readAll())[episodeId] } export async function getAllLocalProgress(): Promise> { return readAll() } export async function saveLocalProgress( episodeId: string, time: number, isWatched: boolean ): Promise { const all = await readAll() all[episodeId] = { time, is_watched: isWatched } await writeAll(all) }