---@diagnostic disable: unused-local
local key = vim.keymap

key.set('n', '<leader>q', ':q<cr>', { desc = '[q]uit' })
key.set('n', '<leader>fs', ':w<cr>', { desc = '[f]ile [s]ave' })
key.set('n', '<leader>fr', ':e<cr>', { desc = '[f]ile [r]efresh' })
key.set('n', '<leader>fx', ':source %<cr>', { desc = '[f]ile e[x]ecute' })

key.set('v', '<leader>er', ':lua<cr>', { desc = '[f]ile [s]ave' })

key.set('n', '<leader>bx', ':source %<cr>', { desc = 'e[x]ecute buffer' })
key.set('n', '<leader>bx', ':source %<cr>', { desc = 'e[x]ecute buffer' })
key.set('n', '<leader>bd', ':bdelete<cr>', { desc = '[b]uffer [d]elete' })
key.set('n', '<leader>bp', ':bprevious<cr>', { desc = '[b]uffer [p]revious' })
key.set('n', '<leader>bn', ':bnext<cr>', { desc = '[b]uffer [n]ext' })

key.set('n', 'j', 'gj')
key.set('n', 'k', 'gk')

key.set('v', '<', '<gv')
key.set('v', '>', '>gv')

key.set('n', 'n', 'nzzzv')
key.set('n', 'N', 'nzzzv')

key.set('v', 'p', '"_dP')

key.set({ 'i', 's' }, '<C-c>', function()
	if vim.snippet then
		vim.snippet.stop()
	end
	return '<esc>'
end)

key.set('n', '<leader>ws', ':split<cr>', { desc = '[w]indow [s]plit horizontally' })
key.set('n', '<leader>wv', ':vsplit<cr>', { desc = '[w]indow split [v]ertically' })
key.set('n', '<leader>wh', '<C-w><C-h>', { desc = 'move focus to left window' })
key.set('n', '<leader>wj', '<C-w><C-j>', { desc = 'move focus to bottom window' })
key.set('n', '<leader>wk', '<C-w><C-k>', { desc = 'move focus to top window' })
key.set('n', '<leader>wl', '<C-w><C-l>', { desc = 'move focus to right window' })
key.set('n', '<leader>wc', '<C-w>c', { desc = '[w]indow [c]lose' })
key.set('n', '<leader>wo', '<C-w>o', { desc = '[w]indow make it [o]pen wide' })

key.set('n', '<M-j>', ':cnext<cr>', { desc = 'quickfix next' })
key.set('n', '<M-k>', ':cprev<cr>', { desc = 'quickfix previous' })

key.set('t', '<esc><esc>', '<C-\\><C-n>', { desc = 'easier terminal normal mode' })

local job_id = 0
key.set('n', '<leader>to', function()
	vim.cmd.vnew()
	vim.cmd.term()
	vim.cmd.wincmd 'J'
	vim.api.nvim_win_set_height(0, 13)
	job_id = vim.bo.channel
end, { desc = '[t]erminal [o]pen' })
