import { CONFIG } from '../config.js';

export function loadSave() {
  try {
    return JSON.parse(localStorage.getItem(CONFIG.storageKey)) ?? { highscore: 0, language: 'dk' };
  } catch {
    return { highscore: 0, language: 'dk' };
  }
}

export function saveHighscore(highscore) {
  let save = {};
  try {
    save = JSON.parse(localStorage.getItem(CONFIG.storageKey)) ?? {};
  } catch {
    save = {};
  }
  save.highscore = highscore;
  localStorage.setItem(CONFIG.storageKey, JSON.stringify(save));
}
