/**
 * Whether `/bookmarks` and `/list/{id}` are in multi-select "Select" mode.
 * Module state rather than a route/component prop for the same reason as
 * `map-filters.ts`/`nav.ts`: the kebab menu that toggles this lives in a
 * header component, a separate router landmark from the page that renders
 * the rows, so the two can't share a Lit property directly.
 */
export const LIST_EDIT_MODE_EVENT = 'list-edit-mode'

let editMode = false

export function isEditMode(): boolean {
  return editMode
}

export function toggleEditMode(): void {
  editMode = !editMode
  globalThis.dispatchEvent(new CustomEvent(LIST_EDIT_MODE_EVENT))
}

export function setEditMode(value: boolean): void {
  if (value === editMode) return
  editMode = value
  globalThis.dispatchEvent(new CustomEvent(LIST_EDIT_MODE_EVENT))
}
