vim.g.mapleader = " "
vim.g.maplocalleader = " "
vim.g.which_key_use_floating_win = 1
vim.g.which_key_timeout = 300

local wk = require("whichkey_setup")

local leader_keymap = {
  ["<space>"] = {"<cmd>Telescope find_files<CR>", "Find file"},
  ["<tab><tab>"] = {"<cmd>b#<CR>", "Goto other buffer"},
  ["<CR>"] = {"<cmd>Pounce<CR>", "Pounce"},
  b = {
    name = "+buffers",
    b = {"<cmd>Telescope buffers<CR>", "List buffers"},
    d = {"<cmd>bd<CR>", "Delete buffer"}
  },
  w = {
    name = "+window",
    v = {"<cmd>vsplit<CR>", "Split vertically"},
    s = {"<cmd>split<CR>", "Split horizontally"},
    q = {"<cmd>x<CR>", "Close window"}, -- No unsaved windows!!
    h = {"<cmd>wincmd h<CR>", "Left"},
    j = {"<cmd>wincmd j<CR>", "Down"},
    k = {"<cmd>wincmd k<CR>", "Up"},
    l = {"<cmd>wincmd l<CR>", "Right"},
    H = {"<C-w>H", "Move Left"},
    J = {"<C-w>J", "Move Down"},
    K = {"<C-w>K", "Move Up"},
    L = {"<C-w>L", "Move Right"},
  },
  l = {
    name = "+lsp",
    e = {"<cmd>lua vim.diagnostic.open_float()<CR>", "Show diagnostic at point"},
    h = {"<cmd>lua vim.diagnostic.goto_prev()<CR>", "Goto prev diagnostic"},
    l = {"<cmd>lua vim.diagnostic.goto_next()<CR>", "Goto next diagnostic"},
    q = {"<cmd>Telescope diagnostics<CR>", "Show all diagnostics"},
    a = {"<cmd>lua vim.lsp.add_workspace_folder()<CR>", "Add folder to workspace"},
    r = {"<cmd>lua vim.lsp.remove_workspace_folder()<CR>", "Remove folder from workspace"},
    R = {"<cmd>Telescope lsp_references<CR>", "List references"},
    s = {"<cmd>Telescope lsp_document_symbols<CR>", "List document symbols"},
    S = {"<cmd>Telescope lsp_workspace_symbols<CR>", "List workspace symbols"},
    d = {"<cmd>Telescope lsp_definitions<CR>", "Goto definition"},
  },
  g = {
    name = "+git",
    s = {"<cmd>Telescope git_status<CR>", "Status"},
    g = {"<cmd>Neogit<CR>", "Neogit"},
    c = {"<cmd>Neogit commit<CR>", "Commit"},
  },
}

wk.register_keymap("leader", leader_keymap)
