const STORAGE_KEY = "lottery.player.bearer";

/** sessionStorage：标签页关闭即清空，符合 H5 嵌入主站场景 */
export function persistPlayerBearerToken(raw: string): void {
  try {
    sessionStorage.setItem(STORAGE_KEY, raw.trim());
  } catch {
    /* ignore quota / private mode */
  }
}

export function readPersistedPlayerBearerToken(): string | null {
  try {
    return sessionStorage.getItem(STORAGE_KEY);
  } catch {
    return null;
  }
}

export function clearPersistedPlayerBearerToken(): void {
  try {
    sessionStorage.removeItem(STORAGE_KEY);
  } catch {
    /* ignore */
  }
}
