////
// temporary hack for browser commands

import { scrollback } from "./dom.js"
import { resize } from "./resize.js"
import { autoScroll } from "./scrollback.js"
import { sessionID } from "./session.js"

export const commands: string[] = []

export const browserCommands: Record<string, () => any> = {
  clear: () => scrollback.innerHTML = "",
  commands: () => commands.join(" "),
  fullscreen: () => document.body.requestFullscreen(),
  mode: () => {
    document.body.dataset.mode = document.body.dataset.mode === "tall" ? "cinema" : "tall"
    resize()
    autoScroll()
  },
  reload: () => window.location.reload(),
  session: () => sessionID,
}

export function cacheCommands(cmds: string[]) {
  commands.length = 0
  commands.push(...cmds)
  commands.push(...Object.keys(browserCommands))
  commands.sort()
}