const KEY = "lottery_admin_token";

export function readToken(): string | null {
  if (typeof window === "undefined") {
    return null;
  }
  const raw = window.localStorage.getItem(KEY)?.trim();

  return raw && raw !== "" ? raw : null;
}

export function writeToken(t: string | null): void {
  if (typeof window === "undefined") {
    return;
  }
  if (t && t.trim() !== "") {
    window.localStorage.setItem(KEY, t.trim());
  } else {
    window.localStorage.removeItem(KEY);
  }
}
