-- vim:fileencoding=utf-8:foldmethod=marker

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
	vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"https://github.com/folke/lazy.nvim.git",
		"--branch=stable",
		lazypath,
	})
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	--: Behaviour {{{
	{
		"folke/lazydev.nvim",
		ft = "lua",
		dependencies = { { "Bilal2453/luvit-meta", lazy = true } },
		opts = {
			library = {
				{ path = "luvit-meta/library", words = { "vim%.uv" } },
			},
		},
	},
	{
		"MeanderingProgrammer/render-markdown.nvim",
		dependencies = { "nvim-treesitter/nvim-treesitter", "echasnovski/mini.icons" }, -- if you use standalone mini plugins
		---@module 'render-markdown'
		---@type render.md.UserConfig
		opts = {},
	},
	{
		"hrsh7th/nvim-cmp",
		dependencies = {
			"hrsh7th/cmp-buffer",
			"hrsh7th/cmp-nvim-lsp",
			"hrsh7th/cmp-cmdline",
			"hrsh7th/cmp-path",
			"hrsh7th/cmp-nvim-lua",
			"hrsh7th/cmp-nvim-lsp-signature-help",
			"hrsh7th/cmp-vsnip",
			"hrsh7th/vim-vsnip",
			"petertriho/cmp-git",
		},
		init = function()
			require("nvim-cmp-config")
		end,
	},
	"VonHeikemen/lsp-zero.nvim",
	{
		"nvim-treesitter/nvim-treesitter",
		build = ":TSUpdate",
		lazy = false,
		opts = {
			highlight = {
				enable = true,
				additional_vim_regex_highlighting = false,
			},
			ensure_installed = {
				"c",
				"lua",
				"vim",
				"vimdoc",
				"query",
				"json",
				"javascript",
				"typescript",
				"json5",
				"jsonc",
				"xml",
				"html",
				"zig",
				"rust",
				"qmljs",
			},
			auto_install = true,
		},
		config = function(_, opts)
			require("nvim-treesitter.configs").setup(opts)
		end,
	},
	{
		"neovim/nvim-lspconfig", -- Configurations for Nvim LSP
		init = function()
			require("nvim-lsp-config")
		end,
	},
	{ "simrat39/rust-tools.nvim", ft = "rust" },
	"preservim/nerdcommenter", -- (batch)commenting tool
	{ -- fuzzy file finder
		"nvim-telescope/telescope.nvim",
		opts = {
			pickers = {
				find_files = {
					--hidden = true,
					no_ignore = true,
				},
			},
		},
	},
	{
		"nvim-telescope/telescope-file-browser.nvim",
		dependencies = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" },
		opts = {
			extensions = {
				file_browser = {
					theme = "ivy",
					hijack_netrw = true,
					auto_depth = true,
					no_ignore = false,
					hidden = { file_browser = true, folder_browser = true },
				},
			},
		},
		config = function(_, opts)
			require("telescope").setup(opts)
			require("telescope").load_extension("file_browser")
		end,
	},
	{
		"folke/trouble.nvim",
		dependencies = { "nvim-tree/nvim-web-devicons" },
		opts = {
			auto_close = true,
			modes = {
				diagnostics = {
					auto_open = false,
				},
			},

			win = { position = "right" },
		},
	},
	{
		"folke/which-key.nvim",
		event = "VeryLazy",
		init = function()
			vim.o.timeout = true
			vim.o.timeoutlen = 300
		end,
		opts = {},
		config = function(_, opts)
			require("which-key-config")
			require("which-key").setup(opts)
		end,
	},
	{
		"mhartington/formatter.nvim",
		config = function()
			local opts = require("formatter-config").build()

			require("formatter").setup(opts)
		end,
	},
	{
		"direnv/direnv.vim",
	},
	{
		"akinsho/toggleterm.nvim",
		version = "*",
		opts = {
			direction = "float",
		},
		config = function(_, opts)
			local Terminal = require("toggleterm.terminal").Terminal
			local lazygit = Terminal:new({ cmd = "lazygit", hidden = true, direction = "float" })

			function _Lazygit_toggle()
				lazygit:toggle()
			end

			require("toggleterm").setup(opts)
		end,
	},
	--:}}}
	--: Visuals {{{
	{
		"rachartier/tiny-inline-diagnostic.nvim",
		event = "VeryLazy", -- Or `LspAttach`
		opts = {
			options = {
				show_all_diags_on_cursorline = true,
				multilines = true,
				enable_on_insert = true,
				throttle = 0,
			},
		},
		config = function(_, opts)
			require("tiny-inline-diagnostic").setup(opts)
		end,
	},
	{
		"echasnovski/mini.indentscope",
		opts = {},
	},
	{
		"echasnovski/mini.cursorword",
		opts = {},
	},
	{
		"nvim-lualine/lualine.nvim",
		dependencies = { "nvim-tree/nvim-web-devicons" },
		opts = { options = { globalstatus = true } },
	},
	{
		"lewis6991/gitsigns.nvim",
		opts = {},
	},
	{
		"folke/todo-comments.nvim",
		dependencies = { "nvim-lua/plenary.nvim" },
		opts = {},
	},
	{
		"romgrk/barbar.nvim",
		dependencies = {
			"nvim-tree/nvim-web-devicons", -- optional, for file icons
			"lewis6991/gitsigns.nvim",
		},
		opts = {
			-- lazy.nvim will automatically call setup for you. put your options here, anything missing will use the default:
			animation = true,
			-- insert_at_start = true,
			-- …etc.
		},
	},
	{
		-- thin bar indicating an arbitray character limit
		"lukas-reineke/virt-column.nvim",
		opts = {
			virtcolumn = "120,100,80",
			char = "│",
			exclude = {
				buftypes = {},
			},
		},
	},
	{
		"rcarriga/nvim-notify",
		opts = {
			render = "wrapped-compact",
			max_width = function()
				return math.floor(vim.o.columns * 0.5)
			end,
		},
		config = function(_, opts)
			require("notify").setup(opts)
			vim.notify = require("notify")
		end,
	},
	{
		"b0o/incline.nvim",
		config = function()
			require("incline").setup()
			require("incline-config")
		end,
		-- Optional: Lazy load Incline
		event = "VeryLazy",
	},
	{
		"stevearc/dressing.nvim",
	},
	{
		"folke/tokyonight.nvim",
		lazy = false,
		priority = 1000,
		opts = {},
	},
	--:}}}
})

vim.diagnostic.config({
	virtual_text = false,
	signs = true,
	update_in_insert = true,
	underline = true,
	severity_sort = false,
	float = {
		border = "rounded",
		source = true,
		header = "",
		prefix = "",
	},
})

vim.cmd([[colorscheme tokyonight]])