export const CHAT_VIEW_STORAGE_KEY = "codexRemote.chatView";

export function readChatViewPreference(storage = globalThis.localStorage) {
  try {
    return storage?.getItem(CHAT_VIEW_STORAGE_KEY) === "grouped" ? "grouped" : "classic";
  } catch {
    return "classic";
  }
}

export function writeChatViewPreference(storage = globalThis.localStorage, view = "classic") {
  try {
    storage?.setItem(CHAT_VIEW_STORAGE_KEY, view === "grouped" ? "grouped" : "classic");
  } catch {
    // Storage may be unavailable in hardened browser contexts; the in-memory view still works.
  }
}
