---@type Wezterm
local wezterm = require "wezterm"
local act = wezterm.action

return function(config)
  config.key_tables = {
    copy_mode = {
      { key = "$", action = act.CopyMode "MoveToEndOfLineContent" },
      { key = ",", mods = "NONE", action = act.CopyMode "JumpReverse" },
      { key = "/", mods = "NONE", action = act.Search { CaseSensitiveString = "" } },
      { key = "0", mods = "NONE", action = act.CopyMode "MoveToStartOfLine" },
      { key = ";", mods = "NONE", action = act.CopyMode "JumpAgain" },
      { key = "Enter", mods = "NONE", action = act.Multiple { { CopyTo = "Clipboard" }, { CopyMode = "Close" } } },
      { key = "Escape", mods = "NONE", action = act.CopyMode "Close" },
      { key = "Space", mods = "NONE", action = act.CopyMode { SetSelectionMode = "Cell" } },
      { key = "[", mods = "CMD", action = act.CopyMode "Close" },
      { key = "^", action = act.CopyMode "MoveToStartOfLineContent" },
      { key = "b", mods = "CTRL", action = act.CopyMode "PageUp" },
      { key = "b", mods = "NONE", action = act.CopyMode "MoveBackwardWord" },
      { key = "c", mods = "CTRL", action = act.CopyMode "Close" },
      { key = "d", mods = "CTRL", action = act.CopyMode { MoveByPage = 0.1 } },
      { key = "e", mods = "NONE", action = act.CopyMode "MoveForwardWordEnd" },
      { key = "e", mods = "CTRL", action = act.ScrollByLine(1) },
      { key = "f", mods = "CTRL", action = act.CopyMode "PageDown" },
      { key = "f", mods = "NONE", action = act.CopyMode { JumpForward = { prev_char = false } } },
      { key = "f", mods = "SHIFT", action = act.CopyMode { JumpBackward = { prev_char = false } } },
      { key = "g", mods = "NONE", action = act.CopyMode "MoveToScrollbackTop" },
      { key = "g", mods = "SHIFT", action = act.CopyMode "MoveToScrollbackBottom" },
      { key = "h", mods = "NONE", action = act.CopyMode "MoveLeft" },
      { key = "h", mods = "SHIFT", action = act.CopyMode "MoveToViewportTop" },
      { key = "j", mods = "NONE", action = act.CopyMode "MoveDown" },
      { key = "k", mods = "NONE", action = act.CopyMode "MoveUp" },
      { key = "l", mods = "NONE", action = act.CopyMode "MoveRight" },
      { key = "l", mods = "SHIFT", action = act.CopyMode "MoveToViewportBottom" },
      { key = "m", mods = "SHIFT", action = act.CopyMode "MoveToViewportMiddle" },
      { key = "n", mods = "NONE", action = act.CopyMode "NextMatch" },
      { key = "n", mods = "SHIFT", action = act.CopyMode "PriorMatch" },
      { key = "o", mods = "NONE", action = act.CopyMode "MoveToSelectionOtherEndHoriz" },
      { key = "q", mods = "NONE", action = act.CopyMode "Close" },
      { key = "t", mods = "NONE", action = act.CopyMode { JumpForward = { prev_char = true } } },
      { key = "t", mods = "SHIFT", action = act.CopyMode { JumpBackward = { prev_char = true } } },
      { key = "u", mods = "CTRL", action = act.CopyMode { MoveByPage = -0.1 } },
      { key = "v", mods = "CTRL", action = act.CopyMode { SetSelectionMode = "Block" } },
      { key = "v", mods = "NONE", action = act.CopyMode { SetSelectionMode = "Cell" } },
      { key = "v", mods = "SHIFT", action = act.CopyMode { SetSelectionMode = "Line" } },
      { key = "w", mods = "NONE", action = act.CopyMode "MoveForwardWord" },
      { key = "y", mods = "NONE", action = act.Multiple { { CopyTo = "Clipboard" }, { CopyMode = "Close" } } },
      { key = "y", mods = "CTRL", action = act.ScrollByLine(-1) },
    },

    search_mode = {
      { key = "Enter", mods = "NONE", action = act.ActivateCopyMode },
      { key = "Escape", mods = "NONE", action = act.CopyMode "Close" },
      { key = "c", mods = "CMD", action = act.Multiple { { CopyTo = "Clipboard" }, { CopyMode = "Close" } } },
      { key = "c", mods = "CTRL", action = act.CopyMode "Close" },
      { key = "e", mods = "NONE", action = act.CopyMode "EditPattern" },
      { key = "n", mods = "CTRL", action = act.CopyMode "NextMatch" },
      { key = "p", mods = "CTRL", action = act.CopyMode "PriorMatch" },
      { key = "r", mods = "CTRL", action = act.CopyMode "CycleMatchType" },
      { key = "u", mods = "CTRL", action = act.CopyMode "ClearPattern" },
      { key = "v", mods = "CMD", action = act.PasteFrom "Clipboard" },
    },

    resize_pane = {
      { key = "Escape", mods = "NONE", action = act.PopKeyTable },
      { key = "c", mods = "CTRL", action = act.PopKeyTable },
      { key = "h", mods = "NONE", action = act.AdjustPaneSize { "Left", 1 } },
      { key = "h", mods = "SHIFT", action = act.AdjustPaneSize { "Left", 10 } },
      { key = "j", mods = "NONE", action = act.AdjustPaneSize { "Down", 1 } },
      { key = "j", mods = "SHIFT", action = act.AdjustPaneSize { "Down", 10 } },
      { key = "k", mods = "NONE", action = act.AdjustPaneSize { "Up", 1 } },
      { key = "k", mods = "SHIFT", action = act.AdjustPaneSize { "Up", 5 } },
      { key = "l", mods = "NONE", action = act.AdjustPaneSize { "Right", 1 } },
      { key = "l", mods = "SHIFT", action = act.AdjustPaneSize { "Right", 5 } },
      { key = "q", mods = "NONE", action = act.PopKeyTable },
      { key = "r", mods = "CMD", action = act.PopKeyTable },
    },
  }
end
