local vim = vim

vim.keymap.set("n", "<C-w>s", function()
	vim.cmd("split")
	vim.cmd("wincmd j")
end, { noremap = true })

vim.keymap.set("n", "<C-w>v", function()
	vim.cmd("vsplit")
	vim.cmd("wincmd l")
end, { noremap = true })

-- Leader Maps
vim.keymap.set("n", "<leader>f", "", { desc = "Files"})
vim.keymap.set("n", "<leader>ff", ":FzfLua files<CR>", { desc = "File Finder"})
-- vim.keymap.set("n", "<leader>fe", ":Pick files<CR>", { desc = "File Picker"})
vim.keymap.set("n", "<leader>ft", t3_toggle_netrw, { desc = "File Tree"})

vim.keymap.set("n", "<leader>b", "", { desc = "Buffers"})
vim.keymap.set("n", "<leader>bb", ":Pick buffers<CR>", { desc = "Buffer Picker"})
vim.keymap.set("n", "<leader>bp", ":bp<CR>", { desc = "Previous"})
vim.keymap.set("n", "<leader>bn", ":bn<CR>", { desc = "Next"})
vim.keymap.set("n", "<leader>bd", ":bd<CR>", { desc = "Delete"})

vim.keymap.set("n", "<leader>g", "", { desc = "Grep"})
vim.keymap.set("n", "<leader>gg", ":FzfLua grep<CR>", { desc = "Grep"})
vim.keymap.set("n", "<leader>gr", ":FzfLua grep resume=true<CR>", { desc = "Resume Grep"})

vim.keymap.set("n", "<leader>G", "", { desc = "Git"})
vim.keymap.set("n", "<leader>Gg", ":LazyGit<CR>", { desc = "LazyGit"})
vim.keymap.set("n", "<leader>GC", ":LazyGitConfig<CR>", { desc = "LazyGit Config"})
vim.keymap.set("n", "<leader>Gc", ":LazyGitFilter<CR>", { desc = "Commits"})
vim.keymap.set("n", "<leader>Gl", ":LazyGitLog<CR>", { desc = "Log"})

vim.keymap.set("n", "<leader><Tab>", "", { desc = "Tabs"})
vim.keymap.set("n", "<leader><Tab><Tab>", ":tabnew<CR>", { desc = "New Tab"})
vim.keymap.set("n", "<leader><Tab>p", ":tabprevious<CR>", { desc = "Previous Tab"})
vim.keymap.set("n", "<leader><Tab>n", ":tabnext<CR>", { desc = "Next Tab"})
vim.keymap.set("n", "<leader><Tab>d", ":tabclose<CR>", { desc = "Delete Tab"})
vim.keymap.set("n", "<leader><Tab>l", ":tablast<CR>", { desc = "Last Tab"})
vim.keymap.set("n", "<leader><Tab>f", ":tabfirst<CR>", { desc = "First Tab"})
vim.keymap.set("n", "<leader><Tab>m", ":tabmove<CR>", { desc = "Move Tab"})
vim.keymap.set("n", "<leader><Tab>r", ":tabrenumber<CR>", { desc = "Renumber Tabs"})
vim.keymap.set("n", "<leader><Tab>c", ":tabclose!<CR>", { desc = "Force Close Tab"})

vim.keymap.set("n", "gR", "<CMD>Glance references<CR>", { desc = "Glance References" })
vim.keymap.set("n", "gD", "<CMD>Glance definitions<CR>", { desc = "Glance Definitions" })
vim.keymap.set("n", "gY", "<CMD>Glance type_definitions<CR>", { desc = "Glance Type Definitions" })
vim.keymap.set("n", "gM", "<CMD>Glance implementations<CR>", { desc = "Glance Implementations" })

vim.keymap.set("n", "<A-Tab>", ":b#<CR>", { desc = "Switch to Last Buffer" })
vim.keymap.set("n", "<A-Left>", ":bprevious<CR>", { desc = "Previous Buffer" })
vim.keymap.set("n", "<A-Right>", ":bnext<CR>", { desc = "Next Buffer" })
vim.keymap.set("n", "<A-Up>", ":tabprevious<CR>", { desc = "Previous Tab" })
vim.keymap.set("n", "<A-Down>", ":tabnext<CR>", { desc = "Next Tab" })
vim.keymap.set("n", "<A-1>", "<Cmd>BufferGoto 1<CR>", { desc = "Go to Buffer 1" })
vim.keymap.set("n", "<A-2>", "<Cmd>BufferGoto 2<CR>", { desc = "Go to Buffer 2" })
vim.keymap.set("n", "<A-3>", "<Cmd>BufferGoto 3<CR>", { desc = "Go to Buffer 3" })
vim.keymap.set("n", "<A-4>", "<Cmd>BufferGoto 4<CR>", { desc = "Go to Buffer 4" })
vim.keymap.set("n", "<A-5>", "<Cmd>BufferGoto 5<CR>", { desc = "Go to Buffer 5" })
vim.keymap.set("n", "<A-6>", "<Cmd>BufferGoto 6<CR>", { desc = "Go to Buffer 6" })
vim.keymap.set("n", "<A-7>", "<Cmd>BufferGoto 7<CR>", { desc = "Go to Buffer 7" })
vim.keymap.set("n", "<A-8>", "<Cmd>BufferGoto 8<CR>", { desc = "Go to Buffer 8" })
vim.keymap.set("n", "<A-9>", "<Cmd>BufferGoto 9<CR>", { desc = "Go to Buffer 9" })
vim.keymap.set("n", "<A-0>", "<Cmd>BufferLast<CR>", { desc = "Go to Last Buffer" })


-- CTRL X Maps
vim.keymap.set("n", "<C-x><C-b>", ":Pick buffers<CR>", { desc = "Buffer Picker"})
vim.keymap.set("n", "<C-x><C-f>", ":Pick files<CR>", { desc = "File Picker"})
vim.keymap.set("n", "<C-x><C-h>", ":Pick help<CR>", { desc = "Help Picker"})
vim.keymap.set("n", "<C-x><C-g>", "", { desc = "Grep"})
vim.keymap.set("n", "<C-x><C-g>g", ":Pick grep<CR>", { desc = "Grep"})
vim.keymap.set("n", "<C-x><C-g>l", ":Pick grep_live<CR>", { desc = "Live Grep"})
vim.keymap.set("v", "<C-x><C-c>", ":'<,'>SnipRun<CR>", { silent = true, desc = "Run Selection" })
vim.keymap.set("n", "<C-x><C-c>", ":<Plug>SnipRun<CR>", { desc = "Run Current Line" })
vim.keymap.set("n", "<C-x><C-b>", ":%SnipRun<CR>", { desc = "Run Buffer" })
vim.keymap.set("n", "<C-x><C-k>", "<Plug>SnipReset<CR>", { desc = "Run Buffer" })
vim.keymap.set("n", "<C-x><C-n>", "", { desc = "Notes"})
vim.keymap.set("n", "<C-x><C-n>e", "<cmd>TWEditTask<cr>", { desc = "TaskWarrior Edit", noremap = true, silent = true })
vim.keymap.set("n", "<C-x><C-n>v", "<cmd>TWView<cr>", { desc = "View Tasks", noremap = true, silent = true })
vim.keymap.set("n", "<C-x><C-n>u", "<cmd>TWUpdateCurrent<cr>", { desc="Update Tasks", noremap = true, silent = true })
vim.keymap.set("n", "<C-x><C-n>s", "<cmd>TWSyncTasks<cr>", { desc = "Sync Tasks", noremap = true, silent = true })
vim.keymap.set("n", "<C-x><C-n><c-space>",  "<cmd>TWToggle<cr>",	{ desc = "Toggle Taskwarrior", silent = true })

