const POLLS_KEY = 'votetech_polls'
const VOTES_KEY = 'votetech_votes'
const USER_KEY = 'votetech_user'
const ADMIN_KEY = 'votetech_admin'

export function readJson(key, fallback) {
  try {
    const raw = localStorage.getItem(key)
    return raw ? JSON.parse(raw) : fallback
  } catch {
    return fallback
  }
}

export function writeJson(key, value) {
  localStorage.setItem(key, JSON.stringify(value))
}

export const storageKeys = { POLLS_KEY, VOTES_KEY, USER_KEY, ADMIN_KEY }
