const STORAGE_KEY = "calendar_run.backendVersion.v1";

export function readCachedBackendVersion(): string | null {
  try {
    const raw = sessionStorage.getItem(STORAGE_KEY);
    return raw !== null && raw.trim().length > 0 ? raw.trim() : null;
  } catch {
    return null;
  }
}

export function writeCachedBackendVersion(version: string): void {
  try {
    if (version === "недоступна" || version === "не указана") {
      return;
    }
    sessionStorage.setItem(STORAGE_KEY, version);
  } catch {
    // private mode / quota
  }
}
