local vim = vim
vim.g.mapleader = " "
vim.g.maplocalleader = " "

vim.o.number = true
vim.o.relativenumber = true
vim.o.wrap = true
vim.o.linebreak = true

vim.o.ignorecase = true
vim.o.smartcase = true
vim.o.smartindent = true
vim.o.indentexpr = ""
vim.o.inccommand = 'split'

vim.o.clipboard = "unnamedplus"

vim.o.cursorline = true
vim.o.showmode = true
vim.o.hlsearch = false
vim.o.tabstop = 2
vim.o.shiftwidth = 2
vim.g.have_nerd_font = true
vim.o.scrolloff = 10
vim.g.border = "rounded"
vim.o.termguicolors = true

vim.o.switchbuf = "newtab"
vim.o.timeoutlen = 250
vim.o.swapfile = false
vim.o.mouse = "a"
vim.o.undofile = true
vim.o.spell = false

vim.diagnostic.config({
	virtual_text = false,
	float = { source = "always", border = "rounded" },
})

require("config.keymaps")
require("config.autocmds")
require("config.plugins.autosave")
require("config.plugins.autopairs")
require("config.plugins.barbar")
require("config.plugins.blink")
require("config.plugins.dashboard")
require("config.plugins.lualine")
require("config.plugins.mason")
require("config.plugins.mini")
require("config.plugins.nvim-lspconfig")
require("config.plugins.neotree")
require("config.plugins.prettier")
require("config.plugins.telescope")
require("config.plugins.theme")
require("config.plugins.treesitter")
require("config.plugins.venv-selector")
require("config.plugins.markdown-renderer")
require("config.plugins.image")

local enable_providers = {
	"python3_provider",
}

for _, plugin in pairs(enable_providers) do
	vim.g["loaded_" .. plugin] = nil
	vim.cmd("runtime " .. plugin)
end

vim.g.loaded_python3_provider = nil


-- lua... I need to move this
vim.lsp.config("lua_ls", {
	settings = {
		Lua = {
			runtime = {
			},
				version = "LuaJIT",
			diagnostics = {
				globals = {
					"vim",
					"require",
				},
			},
			workspace = {
				library = vim.api.nvim_get_runtime_file("", true),
			},
			telemetry = {
				enable = false,
			},
		},
	},
})


vim.api.nvim_create_autocmd('FileType', {
  pattern = { 'c', 'cpp', 'objc', 'objcpp', 'cuda', 'proto' },
  callback = function()
    vim.lsp.start({
      name = 'clangd',
      cmd = {
        'clangd',
        '--background-index',
        '--clang-tidy',
        '--header-insertion=never',
        -- Mandatory for Arch Linux to find ARM headers
        '--query-driver=/usr/bin/arm-none-eabi*',
      },
      root_dir = vim.fs.dirname(vim.fs.find({ 'compile_commands.json', '.git' }, { upward = true })[1]),
      init_options = {
        fallbackFlags = {
          -- Arch-specific paths (verify 14.2.0 matches your 'ls' output)
          '-isystem', '/usr/arm-none-eabi/include',
          '-isystem', '/usr/arm-none-eabi/include/c++/14.2.0',
          '-isystem', '/usr/arm-none-eabi/include/c++/14.2.0/arm-none-eabi',
          '--target=arm-none-eabi',
        },
      },
    })
  end,
})

vim.cmd("syntax on")

vim.api.nvim_create_autocmd("FileType", {
    callback = function()
        local lang = vim.treesitter.language.get_lang(vim.bo.filetype)
        if lang then
            pcall(vim.treesitter.start)
            
            vim.cmd("syntax on") 
        end
    end,
})
