import { clearSavedServerOrigin } from "../../api-base.js";

const CHANGE_PC_KEY = "codexRemote.changePc";

export function isPcConnectionChangeRequested(storage = globalThis.sessionStorage) {
  try { return storage?.getItem(CHANGE_PC_KEY) === "1"; } catch { return false; }
}

export function requestPcConnectionChange(storage = globalThis.sessionStorage) {
  try { storage?.setItem(CHANGE_PC_KEY, "1"); } catch {}
}

export function clearPcConnectionChangeRequest(storage = globalThis.sessionStorage) {
  try { storage?.removeItem(CHANGE_PC_KEY); } catch {}
}

export function disconnectPcConnection({ localStorage = globalThis.localStorage, sessionStorage = globalThis.sessionStorage } = {}) {
  clearSavedServerOrigin(localStorage);
  clearPcConnectionChangeRequest(sessionStorage);
}
