local map = vim.keymap.set

-- Set mapleader
vim.g.mapleader = " "

-- Disable arrow keys in normal, visual, and insert modes.
local keys = { "<Up>", "<Down>", "<Left>", "<Right>" }
for _, key in ipairs(keys) do
  map({ "n", "i", "v" }, key, "<Nop>", { noremap = true, silent = true })
end

-- Toggle spellcheck (When working with LaTeX/Typst)
local spelllangs = {"es_mx", "en_us"}
local current_index = 1

function ToggleSpell()
  vim.o.spelllang = spelllangs[current_index]
  vim.o.spell = not vim.o.spell
  print("Spellcheck " .. (vim.o.spell and "enabled" or "disabled") .. ": " .. spelllangs[current_index])
end

map("n", "<leader>ts", ":lua ToggleSpell()<CR>", { noremap = true, silent = true })

-- Toggle spellcheck language.
function ToggleSpellLang()
  current_index = (current_index % #spelllangs) + 1
  vim.o.spelllang = spelllangs[current_index]
  print("Spelllang: " .. spelllangs[current_index])
end

map("n", "<Leader>sp", ":lua ToggleSpellLang()<CR>", { noremap = true, silent = true })

-- Open terminal
map("n", "<leader>t", "<cmd>8split | terminal<CR>", { noremap = true, silent = true })

-- Neotree
map("n", "<C-b>", "<cmd>Neotree toggle<CR>", { desc = "open neotree"})

-- Telescope
map("n", "<C-p>", "<cmd>Telescope find_files<CR>", { desc = "telescope find files" })
map("n", "<C-g>", "<cmd>Telescope live_grep<CR>", { desc = "telescope live grep" })

-- Nonels
map("n", "<leader>gf", vim.lsp.buf.format, {})

-- LSP Stuff 
map('n', 'K', vim.lsp.buf.hover, {})
map('n', 'gd', vim.lsp.buf.definition, {})
map({'n', 'v'}, '<space>ca', vim.lsp.buf.code_action, {})
