const TERMINAL_KEY = "meezi_terminal_id";

export function getOrCreateTerminalId(): string {
  if (typeof window === "undefined") return "server";
  let id = localStorage.getItem(TERMINAL_KEY);
  if (!id) {
    id = typeof crypto.randomUUID === "function"
      ? crypto.randomUUID()
      : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
    localStorage.setItem(TERMINAL_KEY, id);
  }
  return id;
}
