-- Tab
vim.opt.tabstop = 2 -- number of visual spaces per TAB
vim.opt.softtabstop = 2 -- number of spacesin tab when editing
vim.opt.shiftwidth = 2 -- insert 4 spaces on a tab
vim.opt.expandtab = true -- tabs are spaces, mainly because of python

-- UI config
vim.opt.number = true -- show absolute number
vim.opt.relativenumber = true -- add numbers to each line on the left side
vim.opt.splitbelow = true -- open new vertical split bottom
vim.opt.splitright = true -- open new horizontal splits right
-- vim.opt.termguicolors = true        -- enabl 24-bit RGB color in the TUI
vim.opt.showmode = false -- we are experienced, wo don't need the "-- INSERT --" mode hint

-- Searching
vim.opt.incsearch = true -- search as characters are entered
vim.opt.hlsearch = false -- do not highlight matches
vim.opt.ignorecase = true -- ignore case in searches by default
vim.opt.smartcase = true -- but make it case sensitive if an uppercase is entered
vim.cmd("set nowrap")

-- -- Keybinds
vim.keymap.set("n", "<C-h>", "<C-w>h", opts)
vim.keymap.set("n", "<C-j>", "<C-w>j", opts)
vim.keymap.set("n", "<C-k>", "<C-w>k", opts)
vim.keymap.set("n", "<C-l>", "<C-w>l", opts)

-- Resize with arrows
-- delta: 2 lines
vim.keymap.set("n", "<C-Up>", ":resize -2<CR>", opts)
vim.keymap.set("n", "<C-Down>", ":resize +2<CR>", opts)
vim.keymap.set("n", "<C-Left>", ":vertical resize -2<CR>", opts)
vim.keymap.set("n", "<C-Right>", ":vertical resize +2<CR>", opts)

vim.keymap.set("i", "jk", "<Esc>", opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)

-- jump to definition
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)

-- code actions
vim.keymap.set("n", "<leader>ca", function()
	require("tiny-code-action").code_action()
end, { noremap = true, silent = true })

-- Lazy
require("config.lazy")

-- require("catppuccin").setup({})
-- vim.cmd.colorscheme("catppuccin")

-- css colors
vim.opt.termguicolors = true
require("nvim-highlight-colors").setup({})

-- Plugin setups
require("lualine").setup()
require("dapui").setup()
require("ibl").setup()
require("toggleterm").setup({})
require("mini.animate").setup()
require('nvim-autopairs').enable()

vim.o.showtabline = 2
require("tabby").setup({
  preset = "tab_only"
})

require("tiny-inline-diagnostic").setup({})

-- conform (code formatter)
require("conform").setup({})

-- flutter
require("flutter-tools").setup({})

-- GO
-- require("go").setup()

------------- -- Debugger
local dap, dapui = require("dap"), require("dapui")
dap.listeners.before.attach.dapui_config = function()
	dapui.open()
end
dap.listeners.before.launch.dapui_config = function()
	dapui.open()
end
dap.listeners.before.event_terminated.dapui_config = function()
	dapui.close()
end
dap.listeners.before.event_exited.dapui_config = function()
	dapui.close()
end

-- c und rust
-- dap.adapters.lldb = {
--   type = 'executable',
--   command = 'lldb', -- adjust as needed, must be absolute path
--   name = 'lldb'
-- }
-- dap.configurations.c = dap.configurations.cpp
-- dap.configurations.rust = dap.configurations.cpp
dap.adapters.gdb = {
	type = "executable",
	command = "gdb",
	args = { "--interpreter=dap", "--eval-command", "set print pretty on" },
}
dap.configurations.cpp = dap.configurations.gdb
dap.configurations.rust = dap.configurations.gdb

--------------------------------------------
-- local builtin = require("telescope.builtin")
local conform = require("conform")
-- Love binds
vim.keymap.set("n", "<leader>lr", ":LoveRun<CR>", { desc = "Love run" })
-- Telescope binds
-- vim.keymap.set("n", "<leader>ff", builtin.find_files, { desc = "Telescope find files" })
-- vim.keymap.set("n", "<leader>fg", builtin.live_grep, { desc = "Telescope live grep" })
-- vim.keymap.set("n", "<leader>fb", ":Telescope file_browser<CR>", { desc = "Telescope file_browser" })
-- vim.keymap.set("n", "<leader>fh", builtin.help_tags, { desc = "Telescope help tags" })
-- vim.keymap.set("n", "<leader>fl", ": Telescope flutter commands<CR>", { desc = "Open Telescope flutter" })
-- vim.keymap.set("n", "<leader>fl", ":Telescope flutter commands<CR>", { desc = "Open Telescope flutter" })
-- Dap binds
vim.keymap.set("n", "<leader>do", dapui.open, { desc = "Open debug overlay" })
vim.keymap.set("n", "<leader>dc", dapui.close, { desc = "Close debug overlay" })
vim.keymap.set("n", "<F5>", dap.toggle_breakpoint, { desc = "Toggle breakpoint" })
vim.keymap.set("n", "<F6>", dap.continue, { desc = "dap Continue" })
vim.keymap.set("n", "<F7>", dap.step_over, { desc = "dap step over" })
vim.keymap.set("n", "<F8>", dap.step_into, { desc = "dap step into" })
-- sudawrite
vim.keymap.set("n", "<leader>sw", ":SudaWrite<CR>", { desc = "Write as sudo" })
-- conform
vim.keymap.set("n", "<leader>cf", conform.format, { desc = "format code" })
-- toggleterm binds
vim.keymap.set("n", "<leader>tf", ":ToggleTerm direction=float <CR>", { desc = "Open floating terminal" })
vim.keymap.set("n", "<leader>tt", ":ToggleTerm direction=tab size=50 <CR>", { desc = "Open terminal in new tab" })
vim.keymap.set("n", "<leader>tv", ":ToggleTerm direction=vertical <CR>", { desc = "Open terminal vertical" })
vim.keymap.set("n", "<leader>ts", ":ToggleTerm direction=vertical <CR>", { desc = "select open terminal" })
-- file explorer binds (nvim-tree)
vim.keymap.set("n", "<leader>fe", ":NvimTreeToggle <CR>", { desc = "Toggle nvim tree" })
-- code actions
vim.keymap.set("n", "<leader>ca", function()
	require("tiny-code-action").code_action()
end, { desc = "Show code actions", noremap = true, silent = true })

-- disable annoying inline type things 
vim.lsp.inlay_hint.enable(false)
vim.diagnostic.config({virtual_text = false})


