/**
 * Reading Mode v2 structural analysis is now the default, always-on
 * behaviour — there is no opt-in left to check. `?lisioReaderV2Off` /
 * `localStorage.lisio_reader_v2 = "0"` remain as an emergency kill switch
 * (e.g. a page whose segmentation misbehaves badly enough that a support
 * request needs a quick way back to the pre-v2 flat renderer) rather than
 * something a caller is expected to opt into. Source-side only — the reader
 * NEVER consults a local flag of its own, it renders whichever shape the
 * payload actually carries (`value.structure` present or not). That is what
 * keeps an already-open reader window (reused across navigations via
 * BCMR_NAVIGATE) from disagreeing with a flag flip mid session. See
 * src/reading-mode.ts's BCMR_INIT_HTML handler.
 */
const STORAGE_KEY = "lisio_reader_v2";
const QUERY_KEY = "lisioReaderV2Off";

export function isReaderV2Enabled(): boolean {
  try {
    if (new URLSearchParams(window.location.search).has(QUERY_KEY)) {
      return false;
    }
  } catch {
    /* location/search unavailable — ignore */
  }
  try {
    return window.localStorage.getItem(STORAGE_KEY) !== "0";
  } catch {
    return true;
  }
}
