--[[
    init.lua - Main Neovim configuration entry point
    
    HOW THIS WORKS:
    1. Bootstrap lazy.nvim (plugin manager)
    2. Load basic settings
    3. Load all plugins from plugins/ directory
    4. Set global keymaps and LSP keymaps
]]

-- ============================================================================
-- STEP 1: BOOTSTRAP LAZY.NVIM
-- ============================================================================
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not 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)

-- ============================================================================
-- STEP 2: LOAD SETTINGS
-- ============================================================================
require("basic-settings")

-- ============================================================================
-- STEP 3: LOAD PLUGINS
-- ============================================================================
require("lazy").setup("plugins")

-- ============================================================================
-- STEP 4: LSP KEYMAPS
-- ============================================================================
vim.keymap.set("n", "gd", vim.lsp.buf.definition, { desc = "Go to definition" })
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, { desc = "Go to declaration" })
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, { desc = "Go to implementation" })
vim.keymap.set("n", "gr", vim.lsp.buf.references, { desc = "Show references" })
vim.keymap.set("n", "K", vim.lsp.buf.hover, { desc = "Show hover docs" })
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, { desc = "Rename symbol" })
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, { desc = "Code actions" })
vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, { desc = "Show diagnostic" })
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Previous diagnostic" })
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Next diagnostic" })

vim.diagnostic.config({
    virtual_text = { prefix = "●" },
    signs = true,
    float = { border = "rounded" },
})

-- ============================================================================
-- STEP 5: GLOBAL KEYMAPS
-- ============================================================================
vim.keymap.set("n", "<leader>w", ":w<CR>", { desc = "Save file" })
vim.keymap.set("n", "<leader>q", ":q<CR>", { desc = "Quit" })
vim.keymap.set("n", "<C-n>", ":Neotree filesystem reveal left<CR>", { desc = "Toggle explorer" })
vim.keymap.set("n", "<C-p>", ":Telescope find_files<CR>", { desc = "Find files" })
