import type { ActiveRoomState } from './state'

const KEY = 'mahjong_active_room'

// 读取缓存
export function readActiveRoomSnapshot(): ActiveRoomState | null {
    const raw = localStorage.getItem(KEY)
    if (!raw) return null

    try {
        return JSON.parse(raw)
    } catch {
        return null
    }
}

// 写入缓存
export function saveActiveRoom(state: ActiveRoomState) {
    localStorage.setItem(KEY, JSON.stringify(state))
}